Create Azure IoT Hub
Sending telemetry data from remote PLC to the outside or to the cloud is pretty hard. Most of the machines are behind locked down networks or behind CGNAT. No way for direct communication to the open internet. Which is good for security but it makes life hard for the Engineers working to collect telemetry data such as recent alarms, production speeds, breaks downs, authentication history and etc.
That's where Azure IoT Hub comes to picture. Works anywhere. Even behind the firewall with secure socket communications with TLC. End user can bring their own certificates.
Getting started​
On Microsoft Azure everything is under a resource group. It helps end user to organise their resources. User might have different production lines in the given factory, resources belongs to each machine or machines can organised into different resource groups.
Create Resource group​
On Azure's portal, select Resource Group.
Click on + Create
to create a new resource group for our IoT Hub.
Enter the name for resource group and select the nearest data centre to your desired location.
It might take up to 2 minutes to complete the task. Once completed, user will receive a notification.
Create IoT Hub​
To create IoT Hub, Go to portal home page or go to all services and select IoT Hub
Click on + Create
to create the IoT hub.
Select the resource group which was created earlier and select the remaining details based on the requirement and click on Review + Create
.
Tier
and Daily Message Limit
can be upgraded in the future. Start with low when testing.
IoT hub name
should be unique, Not only to your account but to the entire Azure Network.
Create IoT Device​
Navigate to created IoT Hub and Select Devices
Under Device Management
. Select Add Device
.
Click save to create device.
Create Module Identity​
Device might have multiple sensors or IO Modules. With modules, data can organised. To add module, Select Add Module Identity
Add relevant name and click save to add the module. Multiple modules can be add to the device and can send the data in between the modules.
Connection​
To connect to the Azure IoT Hub
, PLC
/Motion Controller
needs Client id
, Module id
, Username
and shared access signatures
(SAS token
) as a Password
. By providing SAS
token, access can be limited that particular device.
Client Id​
syntax of client ID to {device-id}/{module-id}
. Here it would plc-001/plc-001-temp-sensor-001
.
Username​
syntax of the Username
is
<hubname>.azure-devices.net/{device_id}/{module_id}/?api-version=2021-04-12
.
Here it would be as following
Si-Iot-Hub--001.azure-devices.net/plc-001/plc-001-temp-sensor-001/?api-version=2021-04-12
Select the latest api-version
available. Selecting wrong version might cause unintentional behaviour.
SAS Token​
To generate SAS Token
, Open Azure CLI
and run following
az iot hub generate-sas-token -n {iothub_name}
Copy the generated token and add it as a password
.
WILL Topic​
To publish messages, WILL
topic is required, syntax as follows.
devices/{device-id}/modules/{module-id}/messages/events/
It would be
devices/plc-001/modules/plc-001-temp-sensor-001/messages/events/
Receiving Messages​
To listen to the messages
devices/{device-id}/modules/{module-id}/#
It would be
devices/plc-001/modules/plc-001-temp-sensor-001/#