MQTT SparkPlug Device Example

Shows how to create a SparkPlug device in Node-red and add a few values

[{"id":"111e698.eea0097","type":"sparkplug","z":"a5f3a40c.298f18","name":"","broker":"tcp://localhost","port":"1883","clientid":"Pinger","groupid":"Sparkplug Devices","edgenode":"Node-RED Edge Node","version":"spBv1.0","enablecache":"true","publishdeath":"true","user":"nodered","password":"nodered","x":427.1667289733887,"y":296.3333492279053,"wires":[["add263a7.9d18b","25c72e8.df6a2d2"]]},{"id":"a3f7a4f8.f16ee8","type":"inject","z":"a5f3a40c.298f18","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":true,"x":95.16667175292969,"y":301,"wires":[["c88e0736.eec2f8"]]},{"id":"c88e0736.eec2f8","type":"function","z":"a5f3a40c.298f18","name":"","func":"msg.topic = \"pinger/DBIRTH\"\nmsg.payload = {\n    \"timestamp\" : Date.now(),\n    \"metrics\" : [\n        {\n            \"name\" : \"google/ping\",\n            \"value\" :-1,\n            \"type\" : \"float\"\n        },\n        {\n            \"name\" : \"facebook/ping\",\n            \"value\" :-1,\n            \"type\" : \"float\"\n        },\n        {\n            \"name\" : \"demo/writeable bool\",\n            \"value\" :false,\n            \"type\" : \"boolean\"\n        }\n    ]\n}\nreturn msg;\n","outputs":1,"noerr":0,"x":239.16668701171875,"y":302.3333435058594,"wires":[["111e698.eea0097"]]},{"id":"5f705084.8eabb","type":"ping","z":"a5f3a40c.298f18","name":"","host":"www.google.com","timer":"1000","x":123.16668701171875,"y":173.66667366027832,"wires":[["209a9d47.8f32e2"]]},{"id":"209a9d47.8f32e2","type":"function","z":"a5f3a40c.298f18","name":"","func":"var np = {\n    \"timestamp\" : Date.now()\n};\nvar metrics = [];\nmetrics.push({\n    \"name\" : \"google/ping\",\n    \"value\" : msg.payload,\n    \"type\" : \"float\"\n});\n\nnp[\"metrics\"] = metrics\nmsg.payload = np\nmsg.topic = \"pinger/DDATA\"\nreturn msg;","outputs":1,"noerr":0,"x":291.1667022705078,"y":176.33335494995117,"wires":[["111e698.eea0097"]]},{"id":"64221948.e2de18","type":"ping","z":"a5f3a40c.298f18","name":"","host":"www.facebook.com","timer":"1000","x":126,"y":110,"wires":[["27db8659.bb2b4a"]]},{"id":"27db8659.bb2b4a","type":"function","z":"a5f3a40c.298f18","name":"","func":"var np = {\n    \"timestamp\" : Date.now()\n};\nvar metrics = [];\nmetrics.push({\n    \"name\" : \"facebook/ping\",\n    \"value\" : msg.payload,\n    \"type\" : \"float\"\n});\n\nnp[\"metrics\"] = metrics\nmsg.payload = np\nmsg.topic = \"pinger/DDATA\"\nreturn msg;","outputs":1,"noerr":0,"x":282,"y":114,"wires":[["111e698.eea0097"]]},{"id":"25c72e8.df6a2d2","type":"debug","z":"a5f3a40c.298f18","name":"","active":true,"console":"false","complete":"true","x":629.1666870117188,"y":298,"wires":[]},{"id":"f8f1f2c8.ea94f","type":"function","z":"a5f3a40c.298f18","name":"","func":"var np = {\n    \"timestamp\" : Date.now()\n};\nvar metrics = [];\nmetrics.push({\n    \"name\" : \"demo/writeable bool\",\n    \"value\" : msg.payload.metrics[0].value,\n    \"type\" : \"boolean\"\n});\n\nnp[\"metrics\"] = metrics\nmsg.payload = np\nmsg.topic = \"pinger/DDATA\"\nreturn msg;","outputs":1,"noerr":0,"x":502.6666564941406,"y":116,"wires":[["111e698.eea0097"]]},{"id":"add263a7.9d18b","type":"switch","z":"a5f3a40c.298f18","name":"","property":"payload.metrics[0].name","propertyType":"msg","rules":[{"t":"eq","v":"demo/writeable bool","vt":"str"},{"t":"eq","v":"rebirth","vt":"str"}],"checkall":"true","outputs":2,"x":535.8333206176758,"y":225.66670036315918,"wires":[["f8f1f2c8.ea94f"],[]]}]

Flow Info

Created 7 years, 2 months ago
Updated 6 years, 5 months ago
Rating: not yet rated

Owner

Actions

Rate:

Node Types

Core
  • debug (x1)
  • function (x4)
  • inject (x1)
  • switch (x1)
Other

Tags

  • Node-red
  • MQTT
  • Ignition
  • SparkPlug
Copy this flow JSON to your clipboard and then import into Node-RED using the Import From > Clipboard (Ctrl-I) menu option