Connecting OPC-UA PLCs to azure iot hub using Moxa UC-8112A IIoT Gateway running Microsoft OPCpublisher Container (Azure IoT Edge + ThingsPro Edge)
- Basic Device Setup
- Cloud Setup
- Setup Provisioning Tool
- Verify Modules on UC-8112A IIoT Gateway
- Data Setup
- Monitor OPC-UA Server D2C Telemetry data from Azure IoT Hub
- username/password: moxa/moxa
- IP LAN1 192.168.3.127
- IP LAN2 192.168.4.127
Reset to factory default
If the unit has been installed prior, we should reset it back to default before installing ThingsPro Edge. The commands listed below is for armhf
and UC-8100A series gateway
mx-set-def
Note: Make sure to have a console cable connected to the device or login via ssh
Remove docker folder
rm -rf /overlayfs/docker /overlayfs/working/docker
Note: This will wipe out all the data on the device!
dhclient eth0
Note: Make sure there is a dhcp server on LAN1
- armhf:
wget https://thingspro.blob.core.windows.net/software/edge/V2.0.0/update_2.0.0-1579-uc-8112a-me-iotedge_armhf.deb dpkg -i ./update_2.0.0-1579-uc-8112a-me-iotedge_armhf.deb
Click on the url below or copy url it on your web browser which starts downloading thingspro software, it takes 10~12 minutes depending the network speed of your internet connection.
https://thingspro.blob.core.windows.net/software/edge/V2.0.0/update_2.0.0-1579-uc-8112a-me-iotedge_armhf.deb
After the download is completed, copy .deb package file on the UC gateway via FTP
Hint: On Windows10 use WinSCP tool. It is free tool available on the url below.
https://winscp.net/eng/download.php
- armhf:
dpkg -i ./update_2.0.0-1579-uc-8112a-me-iotedge_armhf.deb
journalctl -u update -f
Note: The entire process will take about ~11 minutes depends on the hardware/model. When it shows "Stopped MOXA ThingsPro Updater", you can reboot the device by command listed below. The SSH service will be disabled after TPE is installed.
Hint: To enable the SSH service again, please login via local web GUI and enable it from the service enablement option.
sudo reboot
Please use the url below to set up a DPS on azure portal. The url includes three steps.
- Create an Iot hub instance
- Create a new IoT hub DPS
- Link Iot hub and your DPS
https://docs.microsoft.com/en-us/azure/iot-dps/quick-setup-auto-provision
Note: Here we add total two modules for our deployment, one thingspro-agent a system module for device management for Moxa UC-8112A IIOT gateway and second microsoft opcpublisher module for data acquisition
Specify unique name for your deployment then select Next
-
- Image URI:
- armhf:
moxa2019/thingspro-agent:2.0.0-528-armhf
- armhf:
- Container Create Options:
{ "HostConfig": { "Binds": [ "/var/thingspro/apps/cloud/data/setting/:/var/thingspro/cloudsetting/", "/run/:/host/run/", "/var/thingspro/data/:/var/thingspro/data/" ] } }
- Image URI:
-
- Image URI:
- armhf:
mcr.microsoft.com/iotedge/opc-publisher:2.3.0
- armhf:
- Container Create Options:
{ "Hostname": "publisher", "Cmd": [ "--aa" ] }
- Image URI:
-
Modules
After you finished adding the iotedge module, you will redirect to the main page where two iotedge modules were added in the list as you can see in the image below
-
- NAME:
route
- VALUE:
"FROM /messages/* INTO $upstream"
- NAME:
-
- Target Condition:
tags.workshop='Microsoft'
- Target Condition:
Discover and enroll IIoT devices on your designated Azure IoT Hub using Moxa Provision Tool
https://moxaeuiiot.blob.core.windows.net/moxaiiotworkshop/ProvisionTool-20200507.rar
Note: Make sure that notebook is connected on same the local network as shown in the topology. The discovery service works only on LAN1 on UC-8112A IIoT gateway.
-
Modify Configuration File
{ "environment": "prod", "steps": [ { "target": "Predefined", "description": "", "path": "", "method": "provision iot edge using dps", "post": { "scope": "{Service Endpoint of DPS}", "keyName": "{Shared Access Policy}", "key": "{Shared Access keys}", "scopeId": "{ID Scope of DPS}", "iotHubHostName": "{Target IoT Hub}", "initialTwin": { "properties": {}, "tags": { "{Key}": "{Value}" } }, "generateDownstreamCertificate": true, "enableIoTEdge": true } } ] }
-
Device Discovery
-
Select Target Devices
-
Provide Device Credential and Specify Provision Configuration
-
Provision
Note: The provision tool automatically retrieves the Registration ID (SN of the device) and TPM Endorsement key of UC-8112A gateway
-
Verifying the device enrollment status on Azure DPS
-
Verifying the device registration status on Azure DPS
-
Verifying the device registration status on Azure IoT Hub
Note: Device ID is the serial number of the Moxa UC-8112A IIoT gateway
-
Check status IoTEdge Deployment
As you can see in the figure below under "System Metrics"column the deployment has been successfully applied to the device
-
Check IoTEdge device Module Runtime Status
Note: After successfull deployment the iotedge device pull the module images specified in the deployment manifest and start the container from the image. This takes 4~5 minutes depending on the network speed. The iot edge device sends the status updates via reported properties to azure iot hub.
Default credentials
- username/password: admin/admin@123
https://www.virtualbox.org/wiki/Downloads
Download pre-built Debian VM Open Virtualization Appliance (.ova) file running Codesys OPC-UA server
https://moxaeuiiot.blob.core.windows.net/moxaiiotworkshop/Debian10-opcua-server.ova
Note: By deafult the VM is configured 2048 MB RAM, you can reduce the size of the RAM or leave as default settings. Please be patience it takes a few minutes for ova file to be imported. Once the ova file has imported successfully you can start the VM.
-
Start VM
Note: The OPC-UA server will starts automatically when you start the Virtual Machine
The opcua server contains a small PLC program which includes one digital input (Switch) and digital output (Lamp). You can connect to the OPC-UA server locally by using the OPC client UaExpert software as shown in the next section.
The OPC-UA expert software available free from the OPC foundation, by using the OPC-UA client you can browse the address space (Node IDs) of OPC-UA server, read/write data, copy node ID of specific variable and etc. Please check OPC-UA website for further details.
Please use the following link to download the software.
Note: You might need to create an account in order to download the software
https://www.unified-automation.com/downloads/opc-ua-clients.html
-
Setup Connection
Codesys SoftPLC OPC-UA Server IP: 192.168.2.31
-
Discover OPC-UA Server
-
Connected to the Server
-
Browse Address Space OPC-UA Server
Copy NodeID of the lamp_output variable and use this in the payload of the invoke direct method in the next section.
-
Select opcpublisher module from the module list on your iotedge device
-
Select Direct Method
-
Invoke Direct Method
- Method Name:
PublishNodes
- Payload:
{ "OpcNodes": [ { "Id": "ns=4;s=|var|CODESYS Control for Linux SL.Application.PLC_PRG.Lamp_output", "OpcSamplingInterval": 1000, "OpcPublishingInterval": 1000 } ], "EndpointUrl": "opc.tcp://192.168.2.31:4840", "UseSecurity": false }
- Method Name:
https://github.com/Azure/azure-iot-explorer/releases
The opcpublisher module doesn't publish the same data to the IoT Hub rather it publish data on changes. In order to see the lamp_output on change, force the switch input on UaExpert and verify the corresponding output using azure iot explorer as shown in the image below.