Using local node red to get TTN lorawan data through ubidots

 This is kind of cloud data to local data storage.

I have a Lorawan node sending data to TTN. I have it presented on Ubidots . which provide a very good presentation of data and management of device and data.

Ubidots also provide 2 nodes in node red, one to put data to Ubidots, one to receive data from ubidots.

ubidots_out is to send data to ubidots using MQTT

ubidots_in is to receive data from ubidots using MQTT

Getting data to/from Ubidots has a great example:
I have 2 shorts of data on Ubidots, one is direct data integration from TTN, one my local zigbee sensor data uploaded to ubidots using node:ubidots_out.
To receive the 2nd type of data correctly with ubidots in, you will need to add device label in your message payload when using ubitdots out to up load your data.
Othe wise, you can still view the data on the dashboard, but won't be able to down load it.

The 2nd tricky thing is the format returned from unbidots in node, it's not like the my zigbee2mqtt format.There are layers, and each value has it's own sentence.
So need some work to be able to put these data into influxDB.
(the device is the API label of your device on ubidots)




I'm not so familiar with Json manipulation, I tried several errors to redo the message out form ubidots node with a function block:
data and label get correct info from payload, but....

getting close, but still not right, this one will only register humility in influxDB

Finally this one is right..


so with the cofiguration of ubidots node and function, I can get data in my influxDB. But since each value has one msg, so it took a line in database. I think we can do some thing with it in function.

below is the nodes and import code.




[{"id":"948b347c.c35558","type":"ubidots_in","z":"82b75844.2fd748","tier":"business","name":"TTN sensor01 Ubidots in","token":"BBFF-dwBg3A5w4Xi7cHH4Bz27BZ45iB39rM","device_label":"002a9876b6e00ebf","tls_checkbox_in":true,"custom_topic_checkbox":false,"label_variable_1":"temperature","label_variable_2":"humidity","label_variable_3":"lux","label_variable_4":"voltage","label_variable_5":"pressure","label_variable_6":"","label_variable_7":"","label_variable_8":"","label_variable_9":"","label_variable_10":"","checkbox_variable_1_last_value":true,"checkbox_variable_2_last_value":true,"checkbox_variable_3_last_value":true,"checkbox_variable_4_last_value":true,"checkbox_variable_5_last_value":true,"checkbox_variable_6_last_value":true,"checkbox_variable_7_last_value":true,"checkbox_variable_8_last_value":true,"checkbox_variable_9_last_value":true,"checkbox_variable_10_last_value":true,"x":430,"y":140,"wires":[["9fdf9557.29a3a8","7afa6f60.a2847","3e6900c2.d2fb4"]]},{"id":"3e6900c2.d2fb4","type":"function","z":"82b75844.2fd748","name":"function","func":"\nvar payload = msg.payload;\nvar label = Object.keys(payload)[0];\nvar data = payload[label].value;\nvar o={};\no[label]=data;\nmsg.payload=o;\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":440,"y":260,"wires":[["1d978560.83e4bb","8c2e62bc.0b8dc"]]},{"id":"8c2e62bc.0b8dc","type":"influxdb out","z":"82b75844.2fd748","influxdb":"3118462c.ca816a","name":"testinfluxDB","measurement":"testing","precision":"","retentionPolicy":"","x":670,"y":280,"wires":[]},{"id":"1d978560.83e4bb","type":"debug","z":"82b75844.2fd748","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":670,"y":220,"wires":[]},{"id":"3118462c.ca816a","type":"influxdb","hostname":"192.168.0.35","port":"8086","protocol":"http","database":"lorawansensor01","name":"TTN sensor01 to influx","usetls":false,"tls":""}]



留言

這個網誌中的熱門文章

Heltec ESP32+OLED+Lora, hardware testing

micro SD card for ESP32, on lolin32 with OLED and heltec 32 lora oled

AIS0. understanding AIS NMEA 0183: How it's coded