Azure IoT Central Node-RED Connection Node Follow
Overview
The Azure IoT Connection node provides a connection to a configured instance of the Azure IoT Platform for device data collection in the Azure Cloud. The node allows for connection with both Azure IoT Central and Azure IoT hub. This tutorial specifically covers how to configure the node to connect to Azure IoT Central. For more information on configuring the node for Azure IoT Hub, see Azure IoT Hub Node-RED Connection Node. When configured correctly, the node will upload any incoming messages to the Azure IoT Central platform.
This article assumes set up on the Azure IoT Central platform has already been completed. For more information on how to do add a device to Azure, see the example at the end of this article. Knowledge of the following articles is recommended before proceeding.
- MobiusFlow Architecture
- Node-RED Flows
- Mobius Core node-RED Nodes
- Mobius Cloud Format & Store and Forward Nodes
Data Format
The Azure IoT Central platform only accepts data in the form of a single object, where each parameter within the object has an associated value (rather than another object). An example form of an accepted object is shown below.
{
"temperature":15,
"humidity":23,
"parentObject":"",
"name":"",
"objectLastUpdated":"2019-09-06T12:17:05.000Z",
"description":"",
"location":"",
"eep":"A5-04-03",
"uid":"",
"status":0,
"dBm":0,
"lrn":false
}
All parameters that are required in Azure IoT Central should be set up within the object template within Azure. Any parameters that are sent and are not set up within Azure, will be ignored.
Converting from Standard Device Format
This format does not match the standard Mobius cloud data formats. To format this data to be in the correct form, the following setup is recommended.
The Mobius Cloud Format node Mobius Cloud Format & Store and Forward Nodes must be set to minimal verbosity. This ensures only the value of each resource is included in the post-formatted object. The Mobius Cloud Format node also formats the object to list resources by Name instead of by RID.
The change node is set to remove all parts of the message object excluding the resources. The configuration of properties for the change is shown below.
This simply makes the new payload of the message, the resources object of the old message.
After the message passes through both of these nodes, it will now be in a format ready for upload to Azure IoT Central.
Node Properties
The Azure node has 5 properties that require configuration. These are shown in the properties window below.
Connect To
The 'Connect To' property is a drop-down list giving the user the ability to either select Azure IoT Hub or Azure IoT Central. As Azure IoT Hub is not covered within the scope of the article, the selection will be sent to Azure IoT Central.
Scope ID, Device ID & Primary Key
The three credentials can be accessed after setting up a real device within Azure IoT Central. The credentials can be viewed by pressing the connect button on the device page within the Azure IoT Central platform. This is outlined by the red box in the window below.
Within the connection window, the Scope ID, Device ID, and Primary Key are presented.
The three credentials can then be copied into the Azure IoT Connection node.
Connection String
With the Scope ID, Device ID and Primary Key copied into the Azure IoT connection node, the connection string can be automatically generated by clicking the generation button. This is outlined by the red box in the window below.
The final configured state of the node should take the form shown below.
Connection Status
Connected
If configured correctly, the Azure IoT Connection node connects to the device within Azure. The node will show connected status as seen below.
When connection is made, the node will output a message containing the storeFwdControl (msg.storeFwdControl) property. The property is set to 'True' causing any connected Store and Forward nodes enter forwarding mode. A typical setup with a Store and Forward node is shown in the diagram below. For more information on the Store and Forward node Mobius Cloud Format & Store and Forward Nodes.
Disconnected
If the node loses connection, a message will be outputted with the storeFwdControl parameter set to 'False'. This will send the Mobius Store and Forward node into store mode until such a time connection is reestablished.
Example
This example demonstrates how to use the Azure IoT Connection node to send data from a device in Mobius to the Azure IoT Central cloud. This example uses a single Temperature/Humidity sensor which is set up under an EnOcean micro-service. A node-RED connector service has also been set up to connect Mobius Node-RED nodes to Mobius. The configuration for the setup is shown below.
Setting up the device on Azure IoT Central
On the Azure IoT Central page, the device templates tab is selected. This is outlined in red in the window below. Once the device templates tab is selected, the add device template button is selected. This is outlined in orange in the window below.
On the new template page, the custom device template is selected.
The new device is named Temperature/Humidity Sensor to mirror the sensor type used in Mobius. The create button is pressed to create the new device template.
The new template has been created. The addition of telemetry fields is required to represent the measured resources from the Temperature/Humidity sensor. These resources are the Humidity and Temperature. A new telemetry field is created by pressing the 'telemetry' button within the 'new' menu outlined in red in the window below.
Within the create telemetry wizard, the relevant information is added to the telemetry entry. This is shown with the humidity resource below.
Please note, the Field Name must be the same as the resource name within in Mobius.
The same process is followed to add the temperature resource to the device template.
The tab is switched to the devices tab outlined in red below. Ensuring the Temperature/Humidity sensor template is selected, a real device is created using the add real device button outlined in orange below.
In the device creation wizard, the Device ID is set to A5-04-03 to match the EnOcean device type of the Temperature/Humidity sensor. These credentials are not important for data transfer from Mobius to Azure. The create button is then pressed outlined in red in the window below.
The device is now set up and is ready to receive data from Mobius.
Setting up Mobius
The following flow is generated. The flow uses several nodes without explanation. The articles containing more information on the function and usage of these nodes are listed below.
- Set Resource node - See Mobius Core
- Mobius Flow Inject node - See Mobius Core node-RED Nodes
- Mobius Cloud Format - See Mobius Cloud Format & Store and Forward Nodes
- Store and Forward - See Mobius Cloud Format & Store and Forward Nodes
The Azure IoT node is configured for use with the properties found in the previous section of this example. Note, the node shows the connected status to show it has successfully connected to the device within Azure IoT Central.
The two inject nodes, labelled 15 and 16, inject messages to the set resource node which changes the temperature resource (URI - 000001/020/0034/0001/40) of the temperature sensor to 15 or 16 degrees respectively. The inject nodes are set to inject data every few seconds, simulating a sensor with constantly changing reading.
The Mobius Flow Inject node is subscribed to changes in the Temperature/Humidity device so it sends a message whenever the temperature reading changes. The message then passes through the Mobius Cloud Format and change nodes. These nodes prepare the data to be uploaded into the Azure IoT Central cloud (see Data Format section of this article for details).
Finally, the data is relayed by the Store and Forward Node to the Azure IoT connection node ready for upload. The output is fed back into the Store and Forward to automatically stop the Store and Forward node forwarding if connection to Azure is lost (see Connection status page).
Operation
The flow is deployed and the inject nodes begin sending continuous data to simulate a constantly changing temperature reading. This uploads a continuous temperature data stream to Azure IoT Central. Within the azure object previously set up in this example, the continuous stream of temperature data is plotted. This is seen below.
Comments
0 comments
Please sign in to leave a comment.