TTN Data Storage Extraction

Hi,
I must be missing something so I am hoping that this forum will help me in this way.

I’m new to Node Red having installed it on my Raspberry Pi only a few days ago, but having read about it for quite a while and read through a few videos to gain an understanding.

I have a few devices sending data over LoRaWan to TTN. I have added a ‘Data Storage’ to the application on TTN to capture the data and allow for a non real time link between TTN and my Node-Red application. I want to now extract that data from the Data Storage and get it into my Node-Red application on my RPi4. I’ve chosen this route as I believe a MQTT transfer is real time and if my RPi is offline or th network is down, I’ll miss the data.

I can’t figure out how to connect my Node-Red flow to the Data Storage and extract the data. When I hunt around on the internet, all the links point to a TTN deprecated package and nothing else.

I am at a complete loss, something that I thought should be so simple is completely baffling me so any ideas or advice would be greatly appreciated.

Thanks fort any advice in advance.

prerequisite you need:

  • payload decoder with humidity, temperature, timestamp at TTN (according my Proposal for BROWAN TAP SENSOR)
  • in TTN Aplication integration with "Data Storage" https://YOUR_APPLICATION.data.thethingsnetwork.org/
  • Application Access Key from TTN Console
  • running installation node-red with dashboard extension "node-red-dashboard"

Proposed solution : flow downloads data from past 2days and present them in a Line Chart :

[{"id":"21799ec4.0bfbd2","type":"tab","label":"receive_Data","disabled":false,"info":""},{"id":"92272f91.20a43","type":"inject","z":"21799ec4.0bfbd2","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":"","topic":"","payload":"","payloadType":"date","x":100,"y":120,"wires":[["af92df2f.3032e"]]},{"id":"64da113d.24a75","type":"http request","z":"21799ec4.0bfbd2","name":"browan_001","method":"GET","ret":"obj","paytoqs":"ignore","url":"https://YOURAPPLICATION.data.thethingsnetwork.org/api/v2/query/browan001?last=2d","tls":"","persist":false,"proxy":"","authType":"","x":490,"y":120,"wires":[["5ce7a7d2.86be18"]]},{"id":"af92df2f.3032e","type":"function","z":"21799ec4.0bfbd2","name":"set payload and headers","func":"msg.payload = \"data to post\";\nmsg.headers = {};\nmsg.headers['Accept'] = 'application/json';\nmsg.headers['Authorization'] = 'key ttn-account...';\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":290,"y":120,"wires":[["64da113d.24a75"]]},{"id":"31ab53be.5111dc","type":"debug","z":"21799ec4.0bfbd2","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":550,"y":280,"wires":[]},{"id":"5ce7a7d2.86be18","type":"function","z":"21799ec4.0bfbd2","name":"","func":"let temperatures = [];\nlet timestamps = [];\nlet humidities =[];\nfor(let i=0; i<msg.payload.length;i++){humidities.push(msg.payload[i].humidity);temperatures.push(msg.payload[i].temperature);timestamps.push(msg.payload[i].time.slice(0,22));}\n//msg.payload = [temperatures];\nmsg.topic = \"temperature\";\nvar m={};\nm.labels = timestamps;\nm.series = ['Temp', 'Hum'];\nm.data = [temperatures,\n        humidities];\nreturn {payload:[m]};","outputs":1,"noerr":0,"initialize":"","finalize":"","x":520,"y":200,"wires":[["31ab53be.5111dc","c5554621.f1a7c8"]]},{"id":"c5554621.f1a7c8","type":"ui_chart","z":"21799ec4.0bfbd2","name":"","group":"67855681.572f28","order":0,"width":"18","height":"6","label":"chart","chartType":"line","legend":"true","xformat":"HH:mm:ss","interpolate":"linear","nodata":"temperature","dot":true,"ymin":"0","ymax":"85","removeOlder":"1","removeOlderPoints":"","removeOlderUnit":"3600","cutout":0,"useOneColor":false,"useUTC":false,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"useOldStyle":false,"outputs":1,"x":520,"y":340,"wires":[[]]},{"id":"67855681.572f28","type":"ui_group","name":"browan001","tab":"f0beffc3.df851","order":1,"disp":true,"width":"18","collapse":false},{"id":"f0beffc3.df851","type":"ui_tab","name":"Home","icon":"dashboard","disabled":false,"hidden":false}]

Hints:

  • timestamp must comply standard, in my proposal last digits are cut in function handmade
  • for accessing Data via HTTP-Request you need an Authorization header with Application-Key.
  • payload data must fullfill need of line chart

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.