How To Send Telemetry Data From Node-Red To Azure IoT Hub

Node-RED is an open-source flow-based programming tool widely used in IoT projects due to its ease of use and flexibility. One of the most common use cases of Node-RED in IoT is to send data to Azure IoT Hub. Azure IoT Hub is a cloud-based service that enables bidirectional communication between IoT devices and the cloud. This article will explore how to send data to Azure IoT Hub in Node-RED.

Prerequisites

Before we dive into the steps to send data to Azure IoT Hub in Node-RED, let's first review the prerequisites:

  • A Microsoft Azure account
  • Azure IoT Hub instance
  • Node-RED installed and running
  • Node-RED Azure IoT Hub Nodes installed

Step 1. Installing the Azure IoT Hub Nodes

The first step in sending data to Azure IoT Hub in Node-RED is to install the Azure IoT Hub Nodes. These nodes are available as a Node-RED module, which can be installed using the Node-RED Palette Manager.

To install the Azure IoT Hub Nodes, follow these steps:

  1. Open the Node-RED editor and click on the menu icon in the top right corner of the screen.
  2. Select "Manage Palette" from the menu.
  3. Click on the "Install" tab in the Palette Manager.
  4. Search for "node-red-contrib-azureiothubnode" and click on "Install".

How To Send Telemetry Data From Node-Red To Azure IoT Hub

Step 2. Configuring the Azure IoT Hub Nodes

Once the Azure IoT Hub Nodes are installed, the next step is configuring them to connect to your Azure IoT Hub instance.

To configure the Azure IoT Hub Nodes, follow these steps:

  1. Drag the "Azure IoT Hub" node onto the Node-RED canvas.
  2. Double-click on the node to open the configuration panel.
  3. Click the pencil icon next to the "Add new azureiothub-config" field to create a new configuration.
  4. Enter a name for the configuration and provide the connection details for your Azure IoT Hub instance, including the connection string, device ID, and device key.
  5. Click "Add" to save the configuration.

How To Send Telemetry Data From Node-Red To Azure IoT Hub

Step 3. Sending Data to Azure IoT Hub

Once the Azure IoT Hub Nodes are installed and configured, you can send data to Azure IoT Hub.

To send data to Azure IoT Hub, follow these steps,

  1. Create a flow in Node-RED that generates the data you want to send to Azure IoT Hub.
  2. Add an "Azure IoT Hub" node to the flow and connect it to the output of the data-generating node.
  3. Double-click on the "Azure IoT Hub" node to open the configuration panel.
  4. Select the configuration you created in Step 2 from the "azureiothub-config" drop-down menu.
  5. Enter the device ID and message payload in the "Device ID" and "Message Payload" fields.
  6. Click "Deploy" to save the flow and send data to Azure IoT Hub.

How To Send Telemetry Data From Node-Red To Azure IoT Hub

Conclusion

Sending data to Azure IoT Hub in Node-RED is a simple process that can be accomplished using the Azure IoT Hub Nodes. With these nodes, you can quickly connect your IoT devices to Azure IoT Hub and send data to the cloud. By following the steps outlined in this article, you can easily start sending data to Azure IoT Hub in Node-RED.