Creating a Node-RED flow with simulated OPC-UA data

Quick tutorial on how to process Simulated-OPCUA data with node-RED.

1. Creating a OPC-UA Node-RED flow

If you want to download the flow directly, make sure to visit our Node-Red libary.

  1. If you are using a virtual machine type in your browser localhost:1880/noderedor use the port forwarding feature from UMHLens.

  2. If you are using an edge device type in your browser (ip of edge-device):1880/nodered .

  3. You should now see an empty Node-RED flow if everything is working correctly.

    Untitled

  4. The first thing we need to do is add a new palette. To do this, click on the three lines in the upper right corner and select Manage palette. Click on install and add the following node-red-contrib-opcua. Then click on install.

    managepallette.png

    noderedasafsfsafsafa.png

  5. Next, drag an inject node, two function nodes, an opcua-client node and an mqtt-out node into the flow. Connect them as shown in the image below.

    Untitled

  6. FYI:We now create a flow that monitors a Haber-Bosch synthesis.

  7. Open the inject node and select string under msg.topic. Write multiple in the string field and leave the field at msg.payload empty. Now select inject once after 0.1 seconds then at the bottom and click done.

    injectnode.png

  8. Next, open the first function node and add the code below. Once you have done that click Done.

    msg.topic = "multiple";
    msg.payload = [];
    msg.payload.push({nodeId: "ns=2;s=Pressure"});
    msg.payload.push({nodeId: "ns=2;s=ConcentrationH2"});
    msg.payload.push({nodeId: "ns=2;s=ConcentrationN2"});
    msg.payload.push({nodeId: "ns=2;s=ConcentrationNH3"});
    msg.payload.push({nodeId: "ns=2;s=Temperature"});
    return msg;
    
  9. Next, open the opcuaclinet-node and edit the endpoint by clicking on the pencil to the right of it. Enter your opcua-simulator servicename with the associated internal port, select Anonymous and click add. Select SUBSCRIBE under action and click Done.

    opcua_endpoint.jpg

  10. Now open the second function node and paste the code below. Once this is done click Done.

    if (msg.payload && msg.payload.value) {
      var key = msg.topic.replace("ns=2;s=", '')
      var value = msg.payload.value.value;
      var payload =`
      {
        "timestamp_ms":` + Date.now() + `, "` +
        key +`": `+ value + `
      }`
      msg.payload = payload
      msg.topic = "ia/factoryinsight/testLocation/testMachine/processValue/" + key
      return msg;
    }
    
  11. Last but not least open the mqttout node and configure the server with the service name of hivemq as host (located in openlens under services→name) and the port with: 1883. You also have to configure the security tab with username: node-red and password: INSECURE_INSECURE_INSECURE. Click Done.

    mqtt_server_hivemq.jpg

  12. To check if everything works drag a mqtt-in node and a debug node into your flow and connect them. Open the mqtt-in node and select the configured server . Next you need to paste ia/factoryinsight/testLocation/testMachine/processValue/# into topic. Click done and hit deploy on the top right.

  13. Select debug messages located at the top right. If everything works correctly, you should see the simulated OPC-UA data.

    debugkäfer.png

This Node-RED flow will look something like this in Grafana. So make sure you follow our guide so you too can create a dashboard like this.

Untitled

What’s next?

Make sure to go back to our Getting Started page to follow our Getting-Started-Guide!

Next up is Data Visualization, but you can also try out other data-simulators like the PackML-Simulator or the MQTT-Simulator.

Last modified February 17, 2023: update (#208) (ea731fc)