Node red sample to parse The Things Network data

2440large

Before you start please make sure to get your own Node Red instance over here: https://fred.sensetecnic.com

Having your own Node RED instance makes everything much more easier and faster.

This Node Red code reads and parse the node with ID 02014901. This is not our node but just one inside the Things Network.

Basically if you have your own instance you can import below code inside Node Red and tweak it to get everything run.

Make sure to change the clientid field of the MQTT connection.

[{“id”:”8a2ebf56.75d14″,”type”:”mqtt-broker”,”broker”:”croft.thethings.girovito.nl”,”port”:”1883″,”clientid”:””},{“id”:”a8eabe41.57154″,”type”:”mqtt in”,”name”:””,”topic”:”nodes/02014901/packets”,”broker”:”8a2ebf56.75d14″,”x”:128,”y”:67,”z”:”f3306746.0ccf98″,”wires”:[[“d373d2ea.2c8c3”]]},{“id”:”d373d2ea.2c8c3″,”type”:”json”,”name”:””,”x”:334,”y”:139.5,”z”:”f3306746.0ccf98″,”wires”:[[“df05624b.20faa”]]},{“id”:”7be28d4c.841d74″,”type”:”function”,”name”:”decode”,”func”:”msg.payload.data = new Buffer(msg.payload.data, “base64″).toString();nreturn msg;”,”outputs”:1,”noerr”:0,”x”:281.25,”y”:348.25,”z”:”f3306746.0ccf98″,”wires”:[[“d2aff14.f2d501″,”41482b26.beb7d4”]]},{“id”:”41482b26.beb7d4″,”type”:”debug”,”name”:””,”active”:true,”console”:”false”,”complete”:”payload.data”,”x”:490.00000762939453,”y”:644.2500667572021,”z”:”f3306746.0ccf98″,”wires”:[]},{“id”:”df05624b.20faa”,”type”:”switch”,”name”:”Test for Null”,”property”:”payload.data”,”rules”:[{“t”:”nnull”}],”checkall”:”true”,”outputs”:1,”x”:470.03570556640625,”y”:69.57143020629883,”z”:”f3306746.0ccf98″,”wires”:[[“7be28d4c.841d74”]]},{“id”:”d2aff14.f2d501″,”type”:”function”,”name”:”Parse data field Json”,”func”:”var objJson = JSON.parse(msg.payload.data);nmsg.payload.count = objJson.cnt;nmsg.payload.name = objJson.msg;nmsg.payload.battery= objJson.bat;nreturn msg;”,”outputs”:1,”noerr”:0,”x”:471.25000762939453,”y”:295.0000057220459,”z”:”f3306746.0ccf98″,”wires”:[[“5907fe7d.a6f8″,”4b7d6b93.b48294”]]},{“id”:”5907fe7d.a6f8″,”type”:”debug”,”name”:””,”active”:true,”console”:”false”,”complete”:”payload”,”x”:688.7499847412109,”y”:128.74999904632568,”z”:”f3306746.0ccf98″,”wires”:[]},{“id”:”4b7d6b93.b48294″,”type”:”switch”,”name”:”Battery more than 3746″,”property”:”payload.battery”,”rules”:[{“t”:”gt”,”v”:”3746″}],”checkall”:”true”,”outputs”:1,”x”:721.4286575317383,”y”:442.6190576553345,”z”:”f3306746.0ccf98″,”wires”:[[]]}]

Leave a Reply