Using Node-RED Library to Wire Telemetry Data from IoT to the Cloud
Billions of internet-connected devices are deployed annually around the world. As they are interacting with each other, they produce mountains of real-time data that bring valuable insights to businesses. But how can you get the most out of these data flows? Consider using the Node-RED Library.
The massive data streams that are produced by IoT devices can be efficiently processed using flow-based programming. This approach allows for the interconnection of multiple IoT devices, creating a flow between them, and thus the ability to exchange data across predefined connections and networks.
Thanks to the capabilities of the cloud, this approach can facilitate the processing of deep real-time telemetry data pools. Such a solution can be especially useful in asset-intensive industries such as logistics and transportation, automotive, agriculture, utilities, oil, gas and manufacturing.
This article outlines how you can learn to build IoT telemetry simulators for Azure and Amazon cloud platforms using the Node-RED tool. This flow simulator can be used for sending telemetry data to Azure IoT hub and Amazon IoT at the same time.
How to use the Node-RED library for building telemetry data flows
Before you start with development, you need to configure your devices in the Azure IoT hub and the AWS IoT. Use the guidelines provided by Microsoft and Amazon; the links are available for your convenience. Should you have any questions at this point, feel free to leave a comment below.
So, why should you use the Node-RED tool here? It offers a simple way to build quick flows that integrate with different IoT hardware devices and sensors, APIs and online services. At the moment, Node-RED has more than 200,000 modules in its package repository.
The big advantage of using this tool is that you can run it at the edge of the network using low-cost hardware and cloud capabilities. Moreover, Node-RED provides a browser-based editor that allows to easily wire together data flows using the wide range of nodes.
Using Node-RED, you can:
- Run your flows locally using both options: a laptop or a docker.
- Run your flows on various devices, including Arduino, Raspberry PI, etc.
- Run your flows on the cloud of any provider, Amazon, Azure or Google.
Let’s create a flow like this one shown below.
In this flow, the following nodes were used:
- A simple node that sends the message payloads to Azure IoT Hub.
- A node that connects to an MQTT broker and subscribes to messages from the specified topic.
Let’s take a closer look at each node.
The injection node
The payload file type should be JSON. For Azure IoT hub the message needs to look like this:
- The “deviceId” is your device’s unique id.
- The “key” is your device’s primary or secondary key.
- The protocol options are: amqp, amqpws, mqtt or HTTP.
- Data can either be a plain string or a string wrapped JSON.
The function node
The message is passed in as an object called msg. By convention, it will have an msg.payload property containing the body of the message.
Azure IoT hub
In this node, you need to add the name of your Azure IoT hub. Do not forget to select the protocol type — it should be amqp. This node is not installed by default. You need to execute several steps described here.
This node requires the connection to the MQTT broker to be configured. First, you need to configure the server endpoint.
You need to add the connection address of your AWS IoT. After that, you should configure the certificates.
All the necessary certificates can be found in the AWS IoT console.
The last thing you need to do is to deploy the flow by clicking the “Deploy” button.
You can check how the telemetry data comes to Azure and AWS IoT platforms.
Should you have any questions about how you can put this method to work with the telemetry data collected by your IoT networks, please don’t hesitate to get in touch.
By Sergii Bielskyi, Cloud Architect at ELEKS.
Originally published at labs.eleks.com on January 8, 2019.