OPC UA nodes to MQTT topics

I would like to know if through Node Red there is a way to convert the OPC UA nodes into MQTT, because I think that a while ago I saw a video that showed that but in the meantime I looked again and I can't find it.

Have the OPC nodes as input have MQTT node as output.

1 Like

thanks for the help, I was able to send OPC UA data via MQTT protocol.

1 Like

I remembered now if it is possible to convert OPC UA nodes into MQTT topics, isn't it possible to do the opposite ?

how do you think you could do that?

I think using the MQTT block in and then sending it to the OPC UA Server block but on another PC with node red installed to put that PC as OPC UA Server then accessing as OPC UA item, but I don't know if it will be correct my reasoning.

i try make this form but i not have sucess

> [{"id":"a31f4017.b3d74","type":"subflow","name":"String To Number Conversion","info":"","category":"","in":[{"x":197.9999942779541,"y":145.99999618530273,"wires":[{"id":"bd7a0296.a7731"}]}],"out":[{"x":774.9999980926514,"y":144.99999618530273,"wires":[{"id":"69b60903.ccab18","port":0}]}]},{"id":"bd7a0296.a7731","type":"change","z":"a31f4017.b3d74","name":"","rules":[{"t":"set","p":"Topic","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":370.0234375,"y":146.0546875,"wires":[["69b60903.ccab18"]]},{"id":"69b60903.ccab18","type":"change","z":"a31f4017.b3d74","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"$number(payload)","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":587.0234603881836,"y":146.0546932220459,"wires":[[]]},{"id":"54620449.15b3cc","type":"subflow:a31f4017.b3d74","z":"f9beb538.8f3ba8","name":"","x":280,"y":160,"wires":[["ef78a307.23467","fa2c008e.4dee4"]]}]

`

Test you can write from an object node to OPC

I made this little code to test if the value of the defined node appears on the server.
However when I use the OPC UA Client node and set it to WRITE on the server when I deploy the red node stops and I need to start the red node again, I get Ua Expert to connect to the server but I don't get the node ID(topic).

[{"id":"3df509a2.541776","type":"OpcUa-Server","z":"cad9e96.73b1618","port":"53880","name":"","endpoint":"teste","x":774.0000228881836,"y":209.99999809265137,"wires":[["bbbb6534.d3e688"]]}]

That sounds like a problem with the node. Check what messages node-red writes to the log file and then open an issue on the nodes github page so that the author is aware. Copy and paste the error message you find into the issue

I was able to get with the WRITE setting in the OPC UA Client node, now when I inject the variable into the server and try to access the variable with Ua Expert, it just connects to the server and not show the variable (ns=2,s=LM35). I send code and images to be better visible the problem.

[{"id":"a31f4017.b3d74","type":"subflow","name":"String To Number Conversion","info":"","category":"","in":[{"x":197.9999942779541,"y":145.99999618530273,"wires":[{"id":"bd7a0296.a7731"}]}],"out":[{"x":774.9999980926514,"y":144.99999618530273,"wires":[{"id":"69b60903.ccab18","port":0}]}]},{"id":"bd7a0296.a7731","type":"change","z":"a31f4017.b3d74","name":"","rules":[{"t":"set","p":"Topic","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":370.0234375,"y":146.0546875,"wires":[["69b60903.ccab18"]]},{"id":"69b60903.ccab18","type":"change","z":"a31f4017.b3d74","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"$number(payload)","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":587.0234603881836,"y":146.0546932220459,"wires":[[]]},{"id":"e2fa37a4.73a4d8","type":"tab","label":"Flow 2","disabled":false,"info":""},{"id":"c38a99f0.933d08","type":"mqtt in","z":"e2fa37a4.73a4d8","name":"","topic":"LM35","qos":"0","broker":"f6500227.1a06","x":120,"y":100,"wires":[["6ef814ba.7a35dc","203bfaf4.63fac6"]]},{"id":"31482ea6.957402","type":"OpcUa-Client","z":"e2fa37a4.73a4d8","endpoint":"c11ebc18.a5129","action":"write","time":10,"timeUnit":"s","name":"","x":840,"y":220,"wires":[[]]},{"id":"5fa71366.76445c","type":"inject","z":"e2fa37a4.73a4d8","name":"AddVariable","topic":"ns=2;s=LM35;Datatype=Float","payload":"{\"opcuaCommand\":\"add Variable\"}","payloadType":"json","repeat":"","crontab":"","once":true,"onceDelay":0.1,"x":170,"y":400,"wires":[["a316c9eb.6e2668"]]},{"id":"a316c9eb.6e2668","type":"OpcUa-Server","z":"e2fa37a4.73a4d8","port":"53880","name":"","endpoint":"teste","x":400,"y":400,"wires":[[]]},{"id":"b2acb943.a9ff78","type":"ui_gauge","z":"e2fa37a4.73a4d8","name":"","group":"dc6332d.5216ed","order":1,"width":0,"height":0,"gtype":"gage","title":"gauge","label":"units","format":"{{value | number:2}}","min":0,"max":10,"colors":["#00b500","#e6e600","#ca3838"],"seg1":"","seg2":"","x":830,"y":80,"wires":[]},{"id":"411a844b.b6761c","type":"OpcUa-Item","z":"e2fa37a4.73a4d8","item":"ns=2;s=LM35","datatype":"Float","value":"","name":"add Item","x":620,"y":220,"wires":[["31482ea6.957402","b2acb943.a9ff78"]]},{"id":"6ef814ba.7a35dc","type":"subflow:a31f4017.b3d74","z":"e2fa37a4.73a4d8","name":"","x":380,"y":160,"wires":[["411a844b.b6761c"]]},{"id":"203bfaf4.63fac6","type":"debug","z":"e2fa37a4.73a4d8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":420,"y":80,"wires":[]},{"id":"f6500227.1a06","type":"mqtt-broker","z":"","name":"","broker":"10.6.3.3","port":"1883","tls":"","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"c11ebc18.a5129","type":"OpcUa-Endpoint","z":"","endpoint":"opc.tcp://10.6.2.197:53880/teste","secpol":"None","secmode":"NONE","login":false},{"id":"dc6332d.5216ed","type":"ui_group","z":"","name":"Teste","tab":"d25914ce.fbf638","disp":true,"width":"6","collapse":false},{"id":"d25914ce.fbf638","type":"ui_tab","z":"","name":"CompactRIO Sensors","icon":"dashboard","disabled":false,"hidden":false}]

I was able to convert MQTT topics to OPC UA, how can I share my solution?

:smiley: You can add it to flows.nodered.org along with an explanation of what it does.

1 Like

I'm interested in this, can you paste your flow?