Node Red is anybody using?

Is anybody using Node_Red to publish Mqtt (Sparkplug B) data back to Ignition?

If so can you provide some insight?

I’ve used pi’s and node red quite extensively.

Any thing in particular you want to know?. I can share some flows to help you get started.

It’s a bit of a repetitive thing if you have many things you want to send but works well. You have to create the birth message with all those tags then create another part to send those tags on a timer depending how often you want to send the data. That data then appears in ignition designer as tags. You will need to install engine and distributed on your ignition server.

How are you planning on getting the data into node red that you want to send to ignition? If you make all that data into global variables then you can create a flow for MQTT that uses those variables.

I did get my project working as I was expecting.
I use an API to get weather data into node-red.

I am now working on trying to store a few “Data Values” into some registers (Modbus) so that they can be accessed from another modbus server.

Would love to see some of your flows.

I start with something that looks like this,

Code

[{“id”:“804c8ecf.58d13”,“type”:“function”,“z”:“95052e9f.fcbd3”,“name”:“Birth message for this device”,“func”:“var msg={"topic":"Info/DBIRTH",\n"payload":{\n "timestamp": Date.now(),\n "metrics":[{\n "name":"Date",\n "value":global.get("Date"),\n "type":"string",\n "properties":{\n "engUnit":{"value":"C","type":"string"},\n "engHigh":{"value":100,"type":"double"},\n "engLow":{"value":0,"type":"double"}\n }\n },\n {\n "name":"Serial",\n "value":global.get("SerialNumber"),\n "type":"string",\n "properties":{\n "engUnit":{"value":"C","type":"string"},\n "engHigh":{"value":100,"type":"double"},\n "engLow":{"value":0,"type":"double"}\n }\n },\n {\n "name":"Output01",\n "value":false,\n "type":"boolean",\n }]\n }\n \n}\n\nreturn msg;”,“outputs”:1,“noerr”:0,“initialize”:“”,“finalize”:“”,“x”:500,“y”:140,“wires”:[[“360c3cfd.2d6304”,“4b44dbb4.333b74”]]},{“id”:“c87121ba.a8a5b”,“type”:“inject”,“z”:“95052e9f.fcbd3”,“name”:“First scan”,“props”:[{“p”:“payload”}],“repeat”:“600”,“crontab”:“”,“once”:true,“onceDelay”:“1”,“topic”:“”,“payload”:“”,“payloadType”:“date”,“x”:150,“y”:160,“wires”:[[“804c8ecf.58d13”]]},{“id”:“360c3cfd.2d6304”,“type”:“debug”,“z”:“95052e9f.fcbd3”,“name”:“Birth message”,“active”:true,“tosidebar”:true,“console”:false,“tostatus”:false,“complete”:“true”,“targetType”:“full”,“statusVal”:“”,“statusType”:“auto”,“x”:840,“y”:120,“wires”:},{“id”:“cad44469.8777e8”,“type”:“function”,“z”:“95052e9f.fcbd3”,“name”:“Metric value for measurement 2”,“func”:“var msg={"payload":\n{"timestamp": Date.now(),\n"metrics":[{\n "name":"Serial",\n "value":msg.payload,\n "type":"string"}]},\n"topic":"Info/DDATA"}\n\nreturn msg;”,“outputs”:1,“noerr”:0,“initialize”:“”,“finalize”:“”,“x”:490,“y”:500,“wires”:[[“4b44dbb4.333b74”]]},{“id”:“af963d52.329e8”,“type”:“inject”,“z”:“95052e9f.fcbd3”,“name”:“trigger rebirth”,“props”:[{“p”:“payload”},{“p”:“topic”,“vt”:“str”}],“repeat”:“”,“crontab”:“”,“once”:false,“onceDelay”:0.1,“topic”:“”,“payload”:“1337”,“payloadType”:“num”,“x”:150,“y”:120,“wires”:[[“804c8ecf.58d13”]]},{“id”:“b582de5c.2ac72”,“type”:“function”,“z”:“95052e9f.fcbd3”,“name”:“DDEATH”,“func”:“let EquipmentName = "Info"\n\nreturn { "topic" : EquipmentName+"/DDEATH",‘payload’: {"timestamp" : Date.now()} };\n”,“outputs”:1,“noerr”:0,“initialize”:“”,“finalize”:“”,“x”:560,“y”:80,“wires”:[[“4b44dbb4.333b74”]]},{“id”:“fa3841c0.5f279”,“type”:“inject”,“z”:“95052e9f.fcbd3”,“name”:“trigger Death”,“props”:[{“p”:“payload”},{“p”:“topic”,“vt”:“str”}],“repeat”:“”,“crontab”:“”,“once”:false,“onceDelay”:0.1,“topic”:“”,“payload”:“1337”,“payloadType”:“num”,“x”:150,“y”:60,“wires”:[[“b582de5c.2ac72”]]},{“id”:“af7b036f.6b1d”,“type”:“inject”,“z”:“95052e9f.fcbd3”,“name”:“”,“props”:[{“p”:“payload”}],“repeat”:“3600”,“crontab”:“”,“once”:true,“onceDelay”:“2”,“topic”:“”,“payload”:“SerialNumber”,“payloadType”:“global”,“x”:180,“y”:500,“wires”:[[“cad44469.8777e8”]]},{“id”:“f1896e7e.94609”,“type”:“inject”,“z”:“95052e9f.fcbd3”,“name”:“”,“props”:[{“p”:“payload”}],“repeat”:“3600”,“crontab”:“”,“once”:true,“onceDelay”:“2”,“topic”:“”,“payload”:“Date”,“payloadType”:“global”,“x”:150,“y”:440,“wires”:[[“971136e.b0072c8”]]},{“id”:“971136e.b0072c8”,“type”:“function”,“z”:“95052e9f.fcbd3”,“name”:“Metric value for measurement 1”,“func”:“var msg={"payload":\n{"timestamp": Date.now(),\n"metrics":[{\n "name":"Date",\n "value":msg.payload,\n "type":"String"}]},\n"topic":"Info/DDATA"}\n\nreturn msg;”,“outputs”:1,“noerr”:0,“initialize”:“”,“finalize”:“”,“x”:490,“y”:440,“wires”:[[“4b44dbb4.333b74”]]},{“id”:“40b023ea.0cc88c”,“type”:“trigger”,“z”:“95052e9f.fcbd3”,“name”:“”,“op1”:“true”,“op2”:“0”,“op1type”:“str”,“op2type”:“str”,“duration”:“0”,“extend”:false,“units”:“ms”,“reset”:“connecting”,“bytopic”:“all”,“topic”:“topic”,“outputs”:1,“x”:440,“y”:220,“wires”:[[“804c8ecf.58d13”]]},{“id”:“6228611a.df33”,“type”:“status”,“z”:“95052e9f.fcbd3”,“name”:“”,“scope”:[“4b44dbb4.333b74”],“x”:120,“y”:220,“wires”:[[“e02fa785.8fb898”]]},{“id”:“e02fa785.8fb898”,“type”:“function”,“z”:“95052e9f.fcbd3”,“name”:“”,“func”:“str = msg.payload\nmsg.payload = (msg.status);\nmsg.payload = (msg.payload.text);\nreturn msg;\n”,“outputs”:1,“noerr”:0,“initialize”:“”,“finalize”:“”,“x”:280,“y”:220,“wires”:[[“40b023ea.0cc88c”]]},{“id”:“c1591abf.648a58”,“type”:“link in”,“z”:“95052e9f.fcbd3”,“name”:“Sensor 1 In”,“links”:[“7ee403fa.4824ac”],“x”:75,“y”:280,“wires”:[[“b0cbfa1f.3cad68”]]},{“id”:“b0cbfa1f.3cad68”,“type”:“trigger”,“z”:“95052e9f.fcbd3”,“name”:“”,“op1”:“true”,“op2”:“0”,“op1type”:“str”,“op2type”:“str”,“duration”:“0”,“extend”:false,“units”:“ms”,“reset”:“false”,“bytopic”:“all”,“topic”:“topic”,“outputs”:1,“x”:220,“y”:280,“wires”:[[“804c8ecf.58d13”]]},{“id”:“4b44dbb4.333b74”,“type”:“sparkplug”,“z”:“95052e9f.fcbd3”,“name”:“”,“broker”:“tcp:yourserver”,“port”:“1883”,“clientid”:“yourclient”,“groupid”:“your id”,“edgenode”:“your node”,“version”:“spBv1.0”,“enablecache”:“false”,“publishdeath”:“true”,“user”:“user”,“password”:“”,“x”:820,“y”:280,“wires”:[]}]

I create the birth message, then give each value its own inject as I can control how often each message is sent. I include the date/time as that’s a easy way to trigger a transaction group.
To get the data into a global variable i do this…

image

That example comes from the PLC and also shows on the node red dashboard. The code in the function block is

global.set("Call it what you want",msg.payload)

Hope that helps. I have condensed my flow down so if you need any more info I can add more.

Edited to add - If I remember correctly this flow came from another forum member that I found a while back. Cant recall who it was but all credits go to them.

1 Like

Thanks, that adds alot of new thoughts and different ways to approach.