Note: this article has been archived and it is not longer updated. Instructions may not be totally up to date.
Looking for something simple? This tutorial is very complete and contains a lot of detail. If you want something quick and simple, try one of these:
This page contains technical information to help you get familiar with Azure IoT using the Azure IoT Starter Kit - SparkFun ESP8266 Thing Dev Kit (Arduino-compatible). You will find two tutorials that will walk you through different scenarios. The first tutorial will show you how to connect your Azure IoT Starter kit to our Remote Monitoring preconfigured solution from Azure IoT Suite. In the second tutorial, you will leverage Azure IoT services to create your own IoT solution.
You can choose to start with whichever tutorial you want to. If you've never worked with Azure IoT services before, we encourage you to start with the Remote Monitoring solution tutorial, because all of the Azure services will be provisioned for you in a built-in preconfigured solution. Then you can explore how each of the services work by going through the second tutorial.
We hope you enjoy the tutorials! Please provide feedback if there's anything that we can improve.
Don't have a kit yet?: Click here
This tutorial describes the process of taking your SparkFun ESP8266 Thing Dev Kit kit, and using it to develop a temperature, humidity and pressure reader that can communicate with the cloud using the Microsoft Azure IoT SDK.
In this tutorial, you'll be doing the following:
Note: For first time users, click here to get your Azure free trial which gives you 200USD of credit to get started.
Note: Make sure to copy down the names and connection strings mentioned into a text document for reference later.
Note: You may be asked to log back in. This is to ensure your solution has proper permissions associated with your account.
device ID
. In this case we’ll use _“SparkFun_wDHT22”, and then click Check IDdevice ID
, Device Key
, and IoT Hub Hostname
to enter into the code you’ll run on your device later Warning: The Remote Monitoring solution provisions a set of Azure IoT Services in your Azure account. It is meant to reflect a real enterprise architecture and thus its Azure consumption is quite heavy. To avoid unnecessary Azure consumption, we recommend you delete the preconfigured solution in azureiotsuite.com once you are done with your work (since it is easy to recreate). Alternatively, if you want to keep it up and running you can do two things to reduce consumption:
1) Visit this guide to run the solution in demo mode and reduce the Azure consumption.
2) Disable the simulated devices created with the solution (Go to Devices>>Select the device>> on the device details menu on the right, clich on Disable Device. Repeat with all the simulated devices).
3) Stop your remote monitoring solution while you are working on the next steps. (See: Troubleshooting)
Note: Column on the left corresponds to sensor and on the Right to board. On the image, the board is place between 10 and 30 and sensor between 1 and 9.
Start | End | Cable Color |
---|---|---|
VDD (Pin 1G) | Pin 24J | Red cable |
DATA (Pin 2G) | Pin 23J | White cable |
GND (Pin 4G) | Pin 25A | Black cable |
Start | End | Connector |
---|---|---|
DHT22 (Pin 1I) | DHT22 (Pin 4I) | DHT22 |
NULL (Pin 2H) | Pin 1F | 10k Ohm Resistor |
At the end of your work, your SparkFun ESP8266 Thing Dev Kit should be connected with a working sensor. We'll test it in the next sections.
You will need to install the SparkFun ESP8266 Thing Dev Kit board extension for the Arduino IDE:
Note: Make sure that you select "SparkFun ESP8266 Thing Dev" and NOT "SparkFun ESP8266 Thing" in the Arduino IDE (under Tools -> Board)
For this project, we'll also need the following libraries:
To install them, click on the Sketch -> Include Library -> Manage Libraries
. Search for each library using the box in the upper-right to filter your search, click on the found library, and click the "Install" button.
The Adafruit Sensor library is also needed. This can be downloaded here. Instructions for manually installing a library can be found here.
Note: Starting on version 1.0.17, AzureIoTHub
required the AzureIoTUtility
and one of the available protocols. These samples use the AzureIoTProtocol_MQTT
, but it is prepared to work with AzureIoTProtocol_HTTP
too.
remote_monitoring.ino
to open the project in the Arduino IDE.iot_configs.h
, look for the following lines of code:#define IOT_CONFIG_WIFI_SSID "<Your WiFi network SSID or name>"
#define IOT_CONFIG_WIFI_PASSWORD "<Your WiFi network WPA password or WEP key>"
#define IOT_CONFIG_CONNECTION_STRING "HostName=<host_name>.azure-devices.net;DeviceId=<device_id>;SharedAccessKey=<device_key>"
Control-s
Note: As of 1.6.8, the Arduino IDE doesn't properly show "Upload Completed", even when it succeeds.
Note: When first starting you will likely see a “Fetching NTP epoch time failed” error – This is normal, and it trying to sync with Azure. This can take even up to 30 seconds to find a NTP server to sync with. One it is synced, it should start transmitting from there.
Note: Make sure you delete or stop your remote monitoring solution once you have completed this to avoid unnecessary Azure consumption! (See: Troubleshooting)
Please visit our Azure IoT Dev Center for more samples and documentation on Azure IoT.
This tutorial describes the process of taking your Microsoft Azure IoT Starter Kit for the SparkFun ESP8266 Thing Dev Kit, and using it to develop a temperature and humidity reader that can communicate with the cloud using the Microsoft Azure IoT SDK.
This tutorial has the following steps:
Here is a breakdown of the data flow:
The end result will be a functional command center where you can view the history of your device's sensor data, a history of alerts, and send commands back to the device.
Note: Column on the left corresponds to sensor and on the Right to board. On the image, the board is place between 10 and 30 and sensor between 1 and 9. Additionally, when counting the - pins, start from the right and count in, as these do not align with the numbers indicated on the board.
Note: The resistors can change a little from one kit to another, e.g. it can be 330 Ohm (orange, orange, brown) or 560 Ohm (green, blue, brown). Both will work with success.
Start | End | Cable Color |
---|---|---|
VDD (Pin 1G) | Pin 24J | Red cable |
Pin 19A | Pin 6A | Red cable |
DATA (Pin 2G) | Pin 23J | White cable |
GND (Pin 4G) | Pin 1- | Black cable |
GND (Pin 25A) | Pin 21- | Black cable |
Pin 20A | Pin 3A | Green cable |
Start | End | Connector |
---|---|---|
DHT22 (Pin 1I) | DHT22 (Pin 4I) | DHT22 |
NULL (Pin 2H) | Pin 1F | 10k Ohm Resistor |
GRN LED (Pin 2C) | Pin 3C | Green LED |
RED LED (Pin 5C) | Pin 6C | Red LED |
At the end of your work, your SparkFun ESP8266 Thing Dev Kit should be connected with a working sensor. We'll test it in the next sections.
Note: Make sure to copy down the names and connection strings mentioned into a text document for reference later.
Event Hub is an Azure IoT publish-subscribe service that can ingest millions of events per second and stream them into multiple applications, services or devices.
Your choice
(we chose SparkFun2Suite
)Basic
Your choice
Your choice
Your choice
SparkFun2Suite
Event Hub Namespace (or pick any other name that you used)thingdevEventHub
thingdevEventHub
eventhub and go in the Configure tab in the Shared Access Policies section, add a new policy:
readwrite
Send, Listen
readwrite
policy you created.Now we will create a service to store our data in the cloud.
Your choice
(we chose thingdevstorage
)Classic
Standard
Read-access geo-redundant storage (RA-GRS)
Your choice
Your choice
Your choice
Stream Analytics is an Azure IoT service that streams and analyzes data in the cloud. We'll use it to process data coming from your device.
Log on to the Microsoft Azure Portal
In the menu, click New, then click Internet of Things, and then click Stream Analytics Job
Enter a name for the job (We chose “SparkFunStorageJob”), a preferred region, then choose your subscription. At this stage you are also offered to create a new or to use an existing resource group. Choose the resource group you created earlier.
Once the job is created, open your Job’s blade or click on the pinned tile, and find the section titled “Job Topology” and click the Inputs tile. In the Inputs blade, click on Add
Enter the following settings:
TempSensors
Data Stream
IoT Hub
SparkFun2Suite
(use the name for the IoT Hub you create before)iothubowner
iothubowner
primary key can be found in your IoT Hub Settings -> Shared access policiesJSON
UTF-8
Back to the Stream Analytics Job blade, click on the Query tile (next to the Inputs tile). In the Query settings blade, type in the below query and click Save:
SELECT
DeviceId,
EventTime,
MTemperature as TemperatureReading
INTO
TemperatureTableStorage
from TempSensors
WHERE
DeviceId is not null
and EventTime is not null
SELECT
DeviceId,
EventTime,
MTemperature as TemperatureReading
INTO
TemperatureAlertToEventHub
FROM
TempSensors
WHERE MTemperature>25
Note: You can change the 25
to 0
when you're ready to generate alerts to look at. This number represents the temperature in degrees celsius to check for when creating alerts. 25 degrees celsius is 77 degrees fahrenheit.
TemperatureTableStorage
Table Storage
Provide table settings storage manually
thingdevstorage
(The storage account you created earlier)TemperatureRecords
(Your choice - If the table doesn’t already exist, Local Storage will create it)DeviceId
EventTime
1
TemperatureAlertToEventHub
Event Hub
Provide table settings storage manually
SparkFun2Suite
thingdeveventhub
(The Event Hub you made earlier)readwrite
Primary Key for readwrite Policy name
(That's the one you wrote down after creating the event hub)0
JSON
UTF-8
Line separated
Note: Make sure to stop your Command Center jobs once you have when you take a break or finish to avoid unnecessary Azure consumption! (See: Troubleshooting)
sudo apt-get update
sudo apt-get install nodejs
sudo apt-get install npm
git clone https://github.com/Azure-Samples/iot-hub-c-thingdev-getstartedkit.git
command_center_node
folder in your command prompt (cd <path to locally cloned repro>/command_center_node
) and install the required modules by running the following:npm install -g bower
npm install
bower install
Open the config.json
file and replace the information with your project. See the following for instructions on how to retrieve those values.
TemperatureRecords
{
"port": "3000",
"eventHubName": "event-hub-name",
"ehConnString": "Endpoint=sb://name.servicebus.windows.net/;SharedAccessKeyName=readwrite;SharedAccessKey=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa=",
"deviceId": "iot-hub-device-name",
"iotHubConnString": "HostName=iot-hub-name.azure-devices.net;SharedAccessKeyName=service;SharedAccessKey=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa=",
"storageAcountName": "aaaaaaaaaaa",
"storageAccountKey": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa==",
"storageTable": "TemperatureRecords"
}
node server.js
app running on http://localhost:3000
client connected
To deploy this project to the cloud using Azure, you can reference Creating a Node.js web app in Azure App Service.
Next, we will update your device so that it can interact with all the things you just created.
You will need to install the SparkFun ESP8266 Thing Dev Kit board extension for the Arduino IDE:
For this project, we'll also need the following libraries:
To install them, click on the Sketch -> Include Library -> Manage Libraries
. Search for each library using the box in the upper-right to filter your search, click on the found library, and click the "Install" button.
The Adafruit Sensor library is also needed. This can be downloaded here. Instructions for manually installing a library can be found here.
command_center.ino
to open the project in the Arduino IDE.static const char ssid[] = "[Your WiFi network SSID or name]";
static const char pass[] = "[Your WiFi network WPA password or WEP key]";
static const char* connectionString = "[Device Connection String]";
Replace the placeholders with your WiFi name (SSID), WiFi password, and the device connection string you created at the beginning of this tutorial.
Save with Control-s
In the same project, click on the command_center.c
tab to see that file.
Look for the following lines of code:
static const char DeviceId[] = "[Device Name]";
static const char connectionString[] = "[Device Connection String]";
Control-s
Note: As of 1.6.8, the Arduino IDE doesn't properly show "Upload Completed", even when it succeeds.
Head back to your Node application and you will have a fully functional command center, complete with a history of sensor data, alerts that display when the temperature got outside a certain range, and commands that you can send to your device remotely.
Note: Make sure to stop your Command Center jobs once you have when you finish to avoid unnecessary Azure consumption! (See: Troubleshooting)
Please visit our Azure IoT Dev Center for more samples and documentation on Azure IoT.
In this section we will explain how to see the data flowing from the Arduino application to the Node.js application: