IoT Workshop Lab using the NodeMCU (ESP8266) board.
This serves as a working document for the Azure Internet of Things Workshop in which the NodeMCU (ESP8266) Arduino compatible prototyping board is used to connect to Azure IoT.
In this lab, we'll walk through the basics of:
- Creating and configuring an Azure IoT Hub
- Configuring a sample Arduino sketch to communicate with Azure IoT Hub
- Deploying the sketch to the NodeMCU device
- Monitoring the data received from the NodeMCU
- Visualizing and analyzing the IoT data in PowerBI
The following components are required to follow this lab in its entirety.
Note: If you have some experience with prototyping boards and developing Arduino sketches, you can substitute many of the sensors and components in this guide and achieve the same general output. This is the power of Azure IoT Hub - device agnostic support through standards based protocols like AMQP, MQTT, and HTTPS. That being said, the lab is written for use with the following hardware:
- NodeMCU (v1.0)
- Grove Base Shield for NodeMCU (or from Mouser)
- Sensors:
- Temperature/Humidity Sensor (or from Mouser)
- Vibration Sensor (or from Mouser)
- LED Multicolor (or from Mouser)
- Button (or from Mouser)
- Grove cables (or from Mouser)
Similar to the hardware, if you have a preferred Arduino / ESP8266 IDE, you may be able to use an alternative development environment to achieve the goals of this lab, but the instructions are designed with the following in mind:
- Arduino IDE
- ESP8266 Board Package (for Arduino IDE)
- CP210x Driver (if it's not already installed on your system)
- Azure Subscription
- If you already have an Azure Organizational Account, you may use that for this lab.
- If you don't already have an Azure Subscription, you can create a free trial
- Azure Device Explorer
//TODO: Instructions on creating and configuring IoT Hub
- Download the Windows Installer
- Run the
arduino-1.8.2-windows.exe
- Leave the default options selected to install the IDE and supporting drivers
- Leave the default installation Destination Folder unchanged and select
Install
- Wait for the installation to complete. Toward the end of the installation, you may be prompted to install several drivers. Select
Install
for each prompt. - Click
Close
to complete the Arduino IDE installation
- Open the Arduino IDE and click on
File
→Preferences
- Find the
Aditional Boards Manager URLs
and enter the following:http://arduino.esp8266.com/stable/package_esp8266com_index.json
Note: If you already use the Arduino IDE and already have a URL in this field, you can also click the small box to the right of the field to open a larger window to enter the ESP8266 package on a new line. - Click
OK
to close the Preference Screen - Open the menu:
Tools
→Board
→Boards Manager
Note: If this is your first time running the Boards Manager, you may have to wait a moment while it downloads the packages. - Type
ESP8266
in the search box at the top of the Boards Manager screen - Click the
esp8266
record to select the row then selectInstall
to install the package.
Note: The installation may take several minutes as the file is a large download. The version of the esp8266 package used in this lab is 2.3.0 - Open the menu:
Tools
→Board
and selectNodeMCU 1.0
Note: If any of the board configuration settings have been changed, be sure to change them back to the defaults documented below:
-
Board: "NodeMCU 1.0 (ESP-12E Module)"
-
CPU Frequency: "80 MHz"
-
Flash Size: "4M (3M SPIFFS)"
-
Upload Speed: "115200"
-
Port: {see Device Manager}
-
Sketch → Include Library → Manage Libraries
-
Type
azure
in the filter box -
Select each of the below libraries and choose install for each
Library Author Version AzureIoTHub Arduino 1.0.30 AzureIoTProtocol_HTTP Microsoft 1.0.30 AzureIoTProtocol_MQTT Microsoft 1.0.30 AzureIoTUtility Microsoft 1.0.30
- Q: The text in my Serial Port Monitor is all boxes/squares, what should I do?
A: Make sure to select the correct baud rate in the bottom-right corner of the Serial Port Monitor. For this lab, we are using115200
. - Q: I'm getting a
XYZ
error in my Serial Port Monitor, what should I do?
A: Try closing reopening the Serial Port by selecting Tools → Port and then reselecting your desired port. - Q: Are there other debugging steps I can take related to a failed WiFi connection?
A: Set "Debug Port: Serial" and "Debug Level: Core" in the Arduino IDE Tools menu. AddSerial.setDebugOutput(true);
afterSerial.begin(9600);
. This will print additional information from the WiFi stack which may provide hints as to what is going wrong. - Q: How can I check if the WiFi connection is established before connecting?
A: Use the following snippet:if (WiFi.status() != WL_CONNECTED) { WiFi.begin(ssid, password); }
- Q: I'm still having issues connecting to WiFi even after trying the above troubleshooting steps
A: Try the following:WiFi.persistent(false); WiFi.mode(WIFI_OFF); // this is a temporary line, to be removed after SDK update to 1.5.4 WiFi.mode(WIFI_STA); WiFi.begin(ssid, password);
- Q: This isn't working for me on
ESP-01
,ESP-003
, or other alternative board - what can I do?
A: Try adding the following snippet immediately before theWiFi.begin(ssid, password);
line:WiFi.setOutputPower(0);
- Q: Can I set a fallback where the device will broadcast it's own Access Point?
A: Check out the following snippet: AP Fallback GitHub comment