Introduction: Azure IoT Hub and Node-RED - Getting Started With DragonBoard 410c
In this tutorial we will send data to Azure IoT Hub using Node-RED application running on DragonBoard 410c.
The Azure IoT Hub is a fully managed service that enables reliable and secure bi-directional communications between millions of IoT devices and a back-end solution. It also provides comprehensive monitoring for device connectivity and includes device libraries for the most popular languages and platforms.
Node-RED is a visual wiring tool for the Internet of Things designed by IBM, a great tool to who want to develop fast and simple applications.
Step 1: Set Up Azure IoT Hub
Go to you azure portal and lets create an IoT Hub Block to connect, monitor and manage IoT devices.
Click on New -> Internet of Things -> IoT Hub
- Put the name of your Hub
- Select the pricing and scale tier (In this case F1)
- IoT Hub units choose 1
- Device-to-cloud partitions select 2
- Create a new resource group if you dont have yet
- Select your location
- Check pin to dashboard box
If all goes well your IoT Hub block is displayed in your azure portal dashboard!
Step 2: Set Up Node-RED in DragonBoard
Open your browser and go to https://nodered.org/
You will find the steps to install Node-RED in linux devices, so, just open a terminal window in DragonBoard and type:
- $ sudo npm install -g node-red
- $ node-red
After the installation, lets download node-red-contrib-azure-iot-hub, a Node-RED node that allows you to send messages and register devices with Azure IoT Hub.
Go to https://flows.nodered.org/node/node-red-contrib-azure-iot-hub
Install:
- $ npm install node-red-contrib-azure-iot-hub
After the installation, lets run Node-RED:
- node-red
Go to your browser and type 127.0.0.1:1880
In the flow tab, located at the left side of the screen, verifiy if Azure cloud blocks is in there (see in images).
Well, click on the menu button located at the upper right side of the screen and click on Import, Clipboard (see in images). Copy the attached code in there and click on Import button.
Ok, now Double-click the Register Payload node, enter your desired deviceId into the Payload field and click Done. For example: {"deviceId": "DragonBoard"}
Double-click the Azure IoT Hub Registry node, enter your IoT Hub connection string and click Done. (see in images how to get your connection string).
Click on Register Payload node to insert the Device String to Azure IoT Hub Registry node, a message confirming the Device creation notification will be appear in debug log. Save the primary and secondary keys!
Now, double-click on the Send Payload block and put the deviceid that you created in previous step, and the primary key.
Double-Click on Azure IoT Hub node and insert the hostname of your Azure IoT Hub (see in images).
Ok, now your are sending data to your device connected to Azure!!
Attachments
Step 3: Verify the Incomming Data
To verify the data comming from your node-red application, follow the microsoft guide to run a javascript code to receive device-to-cloud messages
https://docs.microsoft.com/en-us/azure/iot-hub/iot-hub-node-node-getstarted
Go to Receive device-to-cloud messages session and run this code, all message sent to the Hub is displayed in your terminal!