Hi @dmwengineering I share with you an example to manage multiples of your NCD pressure and temperature sensors with a single function node and MQTT out node.
[{"id":"372806d2e7c24b76","type":"function","z":"37c8e44a35e28282","name":"ncd to blynk","func":"let mac_device = msg.payload.addr.substring(12);\nmac_device = mac_device.replaceAll(\":\",\"\");\nlet pressure = msg.payload.sensor_data.pressure;\nlet temperature = msg.payload.sensor_data.temperature;\n\nmsg.payload = mac_device;\nnode.send([msg, null]);\n\nmsg = {\n topic: \"ds/\" + mac_device + \"_pressure\",\n payload: pressure\n}\nnode.send([null, msg]);\n\nmsg = {\n topic: \"ds/\" + mac_device + \"_temperature\",\n payload: temperature\n}\nnode.send([null, msg]);","outputs":2,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":970,"y":120,"wires":[["683fd7d271645c11"],[]]},{"id":"683fd7d271645c11","type":"debug","z":"37c8e44a35e28282","name":"mac","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1130,"y":100,"wires":[]}]
You can copy the following JSON code, then go to the main menu in Node-RED, select the import option, then paste the code into the text input box, finally press the import button.
You should connect the output of the “Wireless Gateway” node to the input of the “ncd to blynk” node, as well as the output number 2 of the “ncd to blynk” node to the input of your MQTT node configured with the Blynk credentials.
But be sure this time iside MQTT node to leave the “Topic” property blank, as this time the MQTT topic will be dynamic.
To manage your NCD pressure temperature sensors inside Blynk we are going to use the MAC address, this address is unique in each NCD sensor, we will use it to identify from which sensor the pressure and temperature signal comes from.
I have added a “debug” node called “mac” this node will allow you when a new data arrives from the sensor, to visualize and obtain the last 8 characters of the MAC address of your NCD sensor (you can also observe the MAC address of each device in the physical sensor). You should write down/copy this value, as you will have to use it inside Blynk.
For each sensor you must create its respective element inside Blynk, but this time you must add inside the property “NAME” the last 8 characters of the MAC address of the sensor, underscore and the name of the variable:
For example:
So, in theory, this flow allows you that every time you add a new sensor, you only have to create the object in Blynk adding its MAC address in the identifier NAME, on the Node-RED side you should not add anything, the following image shows how the messages are constructed.
Note: At the moment I don’t have a Blynk account to test the code, please let me know your results.
Please take a look at this, test it, share if it works or let us know if you have any questions.
Thank you,
Eduardo M.