Bridging Data to Microsoft Azure IoT Hub using Neuron

This article will introduce how to use Neuron to bridge data to Microsoft Azure IoT Hub through the public network so that you can easily build IoT applications.

What is Microsoft Azure IoT Hub?

The internet of things (IoT) enables everyday physical objects to connect to the internet and intercommunicate, changing the way we live and work. Azure IoT Hub, a cloud service provided by Microsoft, is a fully managed service that enables organizations to manage, monitor, and control IoT devices.

In addition, Azure IoT Hub enables reliable, secure bidirectional communications between IoT devices and its cloud-based services. It allows developers to receive messages from, and send messages to, IoT devices, acting as a central message hub for communication. It can also help organizations make use of data obtained from IoT devices, transforming IoT data into actionable insights.

Getting started with Azure IoT Hub

Here are the general steps for starting to use Azure IoT Hub.

Setting up Azure IoT Hub

The initial setup process is straightforward. You will need an active Azure subscription. If you do not have one, create a free account.

Once you have an active subscription, log in to the Azure portal. Navigate to the IoT Hub section and click on the Create button. You will need to provide details like the subscription, resource group, region, and name of the IoT Hub. Once these details are filled in, click on the Review + Create button to create your IoT Hub.

Here we create an IoT Hub called emqx-hub, and its hostname is emqx-hub.azure-devices.net.

set up Azure IoT Hub

Registering devices to Azure IoT Hub

Once your Azure IoT Hub is set up, the next step is to register your devices to the Hub.

To register a device, navigate to the IoT devices section in your IoT Hub and click on the Add button. Provide a unique name for the device and click on Save.

Here, we registered a device client-005 for Neuron.

Azure IoT Hub add device

Use Azure IoT Explorer

Once your devices are connected to Azure IoT Hub, they can start sending messages to the Hub. These messages can be telemetry data, like sensor readings, or any other data that you want to send from your devices to the cloud. In the reverse direction, messages could be sent from the Hub to the devices.

We will use Azure IoT Explorer to monitor messages between Azure IoT Hub and Neuron.

The first time you run Azure IoT explorer, you’re prompted for your IoT hub’s connection string. Find the emqx-hub IoT Hub connection string in Azure portal.

Azure IoT Hub connection string

After you add the connection string in Azure IoT Explorer, select Connect.

Azure IoT Explorer connect

Device authentication

IoT Hub uses shared access signature (SAS) tokens to authenticate devices and services to avoid sending keys on the wire. You use SAS tokens to grant time-bounded access to devices and services to specific functionality in IoT Hub. To get authorization to connect to IoT Hub, devices and services must send SAS tokens signed with either a shared access or symmetric key.

Alternatively, Azure IoT Hub can authenticate devices using X.509 certificates. For that to work, you should create and upload certificates first.

Azure IoT Explorer could help generate SAS tokens for convenience.

Azure IoT Explorer SAS token

Configure Neuron

South device

We need some south devices to collect data from. Any Neuron southbound plugin will do for this tutorial, for example, the Modbus TCP plugin.

Add the modbus-tcp Node

Click South Devices -> Add Device to add a node using the Modbus TCP plugin. This tutorial will connect to a modbus simulator at port 60502.

Add modbus node in Neuron dashboard

Create a Group

Click the modbus-tcp node to create a group. We set the group name to group and the interval to 1000.

Add a group to the modbus node in Neuron dashboard

Add tag

Click the created group group to create a tag with the name tag0 and with type INT16.

Add a tag to the modbus node in Neuron dashboard

Finally, check that the modbus-tcp node is in Connected state.

Neuron dashboard sourth devices tab showing modbus node connected

North app

Add the azure Node

Click North Apps -> Add Application to add a node using the Azure IoT plugin.

Add azure node in Neuron dashboard

In the Application Configuration tab, configure the azure node. In order to make MQTT connections to Azure IoT Hub, the Neuron Azure IoT plugin must be provided with either a Shared Access Signature or X.509 Certificates for authentication. Here, we provides a SAS Token.

Neuron dashboard north apps tab

Once the configuration is submitted, the azure node connects to Azure IoT Hub successfully.

azure node connected state in Neuron dashboard

Subscribe to the modbus-tcp Node

Click the azure node, then click Add subscription, select the modbus-tcp node and the group group.

After a device connects, it can send messages to Azure IoT Hub using the MQTT topic devices/{device-id}/messages/events/, where {device-id} is the Device ID of the registered device. In our case, the azure node will publish south device data to the topic devices/client-005/messages/events/.

azure node subscribe to modbus node
azure node subscribe list

Monitor Data

After subscribing to the group group of the modbus-tcp node, the azure node will begin pushing data to the Azure IoT Hub. Click Monitoring, then select the modbus-tcp node and the group group. We see that Neuron reports a initial value 0 for tag0.

Neuron dashboard data monitoring tab

In Azure IoT Explorer, click Telemetry -> Start to view the device to cloud messages. We can check that Azure IoT Hub receives the data correctly.

Azure IoT Explorer telemetry 1

Write Data

In Azure IoT Explorer, click Cloud-to-device message to send a write request to Neuron, which writes value 42 to the tag tag0.

Azure IoT Explorer write

Now we can see that Neuron updates tag0 correctly in the Data monitoring tab.

Neuron dashboard data monitoring tab

And Azure IoT Hub receives the correct tag data, 42, which is expected.

Azure IoT Explorer telemetry 2