Skip to content
PDF

MQTT publisher to OPC UA Server at the node

In this example, temperature and humidity data is provided from a sensor simulation as an MQTT Publisher. The sensor simulation is running on the node. With the Data Services, the data is then provided as OPC UA Server on the node. A development PC with the UaExpert OPC UA Client is used to connect to the OPC UA Server on the node to read the data.

The instructions below cover the following steps:

  • Provisioning an MQTT broker as a Docker workload
  • Provisioning an MQTT Publisher simulation as a Docker workload
  • Deploying the provisioned Docker workloads to the target node
  • Configuring the Data Services Gateway on the node
  • Reading data with the UaExpert OPC UA Client on a development PC

Provisioning and deploying the sensor simulation and the MQTT broker

In the instructions below two Docker workloads will be provisioned and deployed:

An MQTT broker must to be deployed to the node first in order for the sensor simulation to function. The EMQX MQTT broker is used in this example that can be downloaded from the Docker Hub registry.

Afterwards the temperature and humidity sensors simulation MQTT publisher is deployed. Download the Data Services MQTT demo sensor found under Example Applications from the Nerve Software Center. This is the Docker image that is required for provisioning the demo sensor as a Docker workload.

  1. Log in to the Management System. Make sure that the user has the permissions to access the Data Services.
  2. Provision a Docker workload for the EMQX MQTT broker by following Provisioning a Docker workload. This example uses emqx-4.1.0 as the workload name. Use the following workload version settings:

    Setting Value
    Name Enter any name for the workload version.
    Release name Enter any release name.
    DOCKER IMAGE Select From registry and enter emqx/emqx:v4.1.0.
    Container name emqx
    Network name host
  3. Provision a Docker workload for the sensor simulation by following Provisioning a Docker workload. Use the following workload version settings:

    Setting Value
    Name Enter any name for the workload version.
    Release name Enter any release name.
    DOCKER IMAGE Select Upload to add the Docker image of the sensor simulation that has been downloaded before.
    New environment variable Select the + icon and enter the following information:
    • Env. variable
      MQTT_PUB_TOPIC
    • Variable value
      demo-sensor-topic
    Container name ttt-mqtt-demo-sensor-1.0
    Network name host
  4. Deploy both provisioned Docker workloads above by following Deploying a workload.

    Note

    Remember the node name and serial number of the target node. They are needed for the JSON configuration.

Configuring the Data Services Gateway on the node

The input data is a subscription to temperature and humidity variables on the MQTT broker. An OPC UA Server is set up as data output. The input and output are linked in connections.

  1. Access the Local UI on the node. This is Nerve Device specific. Refer to the table below for device specific links to the Local UI. The initial login credentials to the Local UI can be found in the customer profile.

    Nerve Device Physical port Local UI
    MFN 100 P1 http://172.20.2.1:3333
    Kontron KBox A-150-APL LAN 1 <wanip>:3333

    To figure out the IP address of the WAN interface, refer to Finding out the IP address of the device in the Kontron KBox A-150-APL chapter of the device guide.
    Kontron KBox A-250 ETH 2 <wanip>:3333

    To figure out the IP address of the WAN interface, refer to Finding out the IP address of the device in the Kontron KBox A-250 chapter of the device guide.
    Maxtang AXWL10 LAN1 <wanip>:3333

    To figure out the IP address of the WAN interface, refer to Finding out the IP address of the device in the Maxtang AXWL10 chapter of the device guide.
    Siemens SIMATIC IPC127E X1 P1 http://172.20.2.1:3333
    Siemens SIMATIC IPC427E X1 P1 http://172.20.2.1:3333
    Supermicro SuperServer E100-9AP-IA LAN1 <wanip>:3333

    To figure out the IP address of the WAN interface, refer to Finding out the IP address of the device in the Supermicro SuperServer E100-9AP-IA chapter of the device guide.
    Supermicro SuperServer 1019D-16C-FHN13TP LAN3 http://172.20.2.1:3333
    Supermicro SuperServer 5029C-T LAN1 <wanip>:3333

    To figure out the IP address of the WAN interface, refer to Finding out the IP address of the device in the Supermicro SuperServer 5029C-T chapter of the device guide.
    Vecow SPC-5600-i5-8500 LAN 1 http://172.20.2.1:3333
    Winmate EACIL20 LAN1 <wanip>:3333

    To figure out the IP address of the WAN interface, refer to Finding out the IP address of the device in the Winmate EACIL20 chapter of the device guide.
  2. Select Data in the navigation on the left.

    !Local Data Services

  3. Select CONFIGURATION.

  4. Enter the following configuration into the configuration editor of the Gateway:

    {
      "inputs": [
        {
          "type": "MQTT_SUBSCRIBER",
          "name": "emqx_broker_input",
          "clientId": "mqtt_subscriber_0",
          "serverUrl": "tcp://localhost:1883",
          "keepAliveInterval_s": 20,
          "cleanSession": false,
          "qos": 1,
          "connectors": [
            {
              "name": "demo_sensor_connector",
              "topic": "demo-sensor-topic",
              "variables": [
                {
                  "name": "temperature",
                  "type": "int16"
                },
                {
                  "name": "humidity",
                  "type": "uint16"
                }
              ]
            }
          ]
        }
      ],
      "outputs": [
        {
          "type": "OPC_UA_SERVER",
          "name": "opcua_server_output",
          "connectors": [
            {
              "name": "demo_sensor",
              "browseName": "demoSensor",
              "identifier": "s=demoSensor"
            }
          ]
        }
      ],
      "connections": [
        {
          "name": "mqtt_publisher_TO_opcua_server",
          "input": {
            "index": 0,
            "connector": 0
          },
          "output": {
            "index": 0,
            "connector": 0
          }
        }
      ]
    }
    
  5. Select Apply to save the Gateway configuration. The Gateway will restart automatically.

    !Apply Gateway configuration

A success notification pops up in the upper-right to confirm that the Gateway has accepted the configuration and everything works as expected. Select the Logs tab to view the Gateway logs for more information.

!Gateway logs

Reading data with the UaExpert OPC UA Client

The temperature and humidity simulation data can be checked visually using a third party application. This example uses the UaExpert OPC UA Client. Add a new server with the address opc.tcp://172.20.2.1:4840 (here port 4840 is specified as the default of the Gateway) and connect to it. The desired variables are located in the address space, and by adding them to the data access view, their values can be observed.

Note

In order to download the UaExpert OPC UA Client, it is required to create a free account at unified-automation.com.

Before continuing, make sure to follow the UaExpert documentation through the first steps with the UaExpert client. Afterwards follow the instructions below:

  1. Select Server > Add... in the main menu or select the plus icon in the toolbar.

    !Add server

  2. Select Double click to Add Server... under Custom Discovery.

    !Add server

  3. Enter opc.tcp://172.20.2.1:4840. The new server now appears under Custom Discovery.

    !Add server URL

  4. Expand the arrow next to the left of the new server.

    !Expand security policy

  5. Double-click the None security policy. The server configuration now appears in the Project panel under Servers on the left side.

  6. Select the server configuration in the Project panel.
  7. Select Server > Connect in the main menu or select the Connect Server icon in the toolbar to establish a connection to the server.

    !Monitor variables

All connection steps are logged in the Log panel at the bottom. Once connected, the OPC UA Server's address space appears in the Address Space panel on the left. Expand Objects > demoSensor in the Address Space panel on the left and drag-and-drop the temperature and humidity variables to the Data Access View in the middle to monitor their values.

!Monitor variables