Home Labs Stories Using node-red with ST NUCLEO L073RZ Sx1272

USING NODE-RED WITH ST NUCLEO L073RZ SX1272

image story

ABOUT THIS STORY


Posted on Oct. 8, 2017



Beginner
1 Hour

Introduction

Introduction


[ updated Monday 5th March to use new version of node-red TTN module - ttn event/uplink/downlink ]

I have been working with the great loRaWAN combo from STMicroelectronics - a low cost dev board based on a ARM®32-bit Cortex®-M0+ CPU, coupled with the Sx1272 on an Arduino-compatible shield.

Using the online mbed compiler - https://developer.mbed.org/compiler/ , I modded the demo code - LoRaWAN-demo-72 - to add simple output to an OLED display - see photo.

My node-red install runs on a server hosted by https://www.scaleway.com/ that costs around €3/month. I designed a very simple activity monitor - the design of which may help others.

To the basic node-red install, I added node-red-contrib-ttn and node-red-dashboard.

file

Here is the node-red code, remember to insert your own APPID and ACCESS KEY:

[{"id":"cd89d617.a9d0e8","type":"function","z":"546def68.3e374","name":"Extract data","func":"count = {}\nrssi = {}\nsnr = {}\n\n//var b = new Buffer(msg.payload_raw);\n//count.payload = (b[1] << 8 | b[2]).toString();\n//var r = b[3] << 8 | b[4];\n//if ((r & 0x8000) > 0) {\n// r = r - 0x10000;\n//}\n//rssi.payload = r.toString();\n//snr.payload = (b[5]).toString();\n\ncount.payload = msg.counter;\n\nrssi.payload = msg.metadata.gateways[0].rssi;\nsnr.payload = msg.metadata.gateways[0].snr;\n\nreturn [count, rssi, snr];","outputs":"3","noerr":0,"x":230,"y":280,"wires":[["6de8dcb1.29b284"],["72787db7.d4bdf4","a262c4ea.068798"],["21f1441a.e028fc","e6796eca.3e2ec"]]},{"id":"6de8dcb1.29b284","type":"ui_text","z":"546def68.3e374","group":"3d90cd90.e1c9c2","order":7,"width":0,"height":0,"name":"txtCount","label":"Count","format":"{{msg.payload}}","layout":"row-spread","x":440,"y":220,"wires":[]},{"id":"72787db7.d4bdf4","type":"ui_text","z":"546def68.3e374","group":"3d90cd90.e1c9c2","order":5,"width":0,"height":0,"name":"txtRssi","label":"RSSI","format":"{{msg.payload}}","layout":"row-spread","x":430,"y":260,"wires":[]},{"id":"21f1441a.e028fc","type":"ui_text","z":"546def68.3e374","group":"3d90cd90.e1c9c2","order":6,"width":0,"height":0,"name":"txtSnr","label":"SNR","format":"{{msg.payload}}","layout":"row-spread","x":430,"y":340,"wires":[]},{"id":"69c26716.6f6598","type":"ui_text","z":"546def68.3e374","group":"3d90cd90.e1c9c2","order":1,"width":0,"height":0,"name":"txtDevice","label":"Device","format":"{{msg.dev_id}}","layout":"row-spread","x":440,"y":60,"wires":[]},{"id":"89e50c80.55a11","type":"ui_text","z":"546def68.3e374","group":"3d90cd90.e1c9c2","order":3,"width":0,"height":0,"name":"txtDataRate","label":"Data Rate","format":"{{msg.metadata.data_rate}}","layout":"row-spread","x":450,"y":140,"wires":[]},{"id":"d312c0a6.afb48","type":"ui_text","z":"546def68.3e374","group":"3d90cd90.e1c9c2","order":4,"width":0,"height":0,"name":"txtCodingRate","label":"Coding Rate","format":"{{msg.metadata.coding_rate}}","layout":"row-spread","x":460,"y":180,"wires":[]},{"id":"2065149f.497fbc","type":"ui_text","z":"546def68.3e374","group":"3d90cd90.e1c9c2","order":2,"width":0,"height":0,"name":"txtFrequency","label":"Freq.","format":"{{msg.metadata.frequency}}","layout":"row-spread","x":450,"y":100,"wires":[]},{"id":"a262c4ea.068798","type":"ui_chart","z":"546def68.3e374","name":"","group":"3d90cd90.e1c9c2","order":8,"width":0,"height":0,"label":"Signal Strength","chartType":"line","legend":"false","xformat":"HH:mm:ss","interpolate":"linear","nodata":"","dot":false,"ymin":"-150","ymax":"0","removeOlder":1,"removeOlderPoints":"","removeOlderUnit":"3600","cutout":0,"useOneColor":false,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"useOldStyle":true,"x":460,"y":300,"wires":[[],[]]},{"id":"e6796eca.3e2ec","type":"ui_chart","z":"546def68.3e374","name":"SNR","group":"3d90cd90.e1c9c2","order":9,"width":0,"height":0,"label":"Signal:Noise Ratio","chartType":"line","legend":"false","xformat":"HH:mm:ss","interpolate":"linear","nodata":"","dot":false,"ymin":"0","ymax":"10","removeOlder":1,"removeOlderPoints":"500","removeOlderUnit":"3600","cutout":0,"useOneColor":false,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"useOldStyle":true,"x":430,"y":380,"wires":[[],[]]},{"id":"7819848e.fd117c","type":"ttn uplink","z":"546def68.3e374","name":"unosx1272","app":"c7f29eb8.f2f1f","dev_id":"unosx1272","field":"","x":120,"y":60,"wires":[["cd89d617.a9d0e8","69c26716.6f6598","2065149f.497fbc","89e50c80.55a11","d312c0a6.afb48"]]},{"id":"3d90cd90.e1c9c2","type":"ui_group","z":"546def68.3e374","name":"unosx1272","tab":"a104b487.87dca8","order":2,"disp":true,"width":"6","collapse":false},{"id":"c7f29eb8.f2f1f","type":"ttn app","z":"","appId":"<app-id>","accessKey":"<app-key>","discovery":"discovery.thethingsnetwork.org:1900"},{"id":"a104b487.87dca8","type":"ui_tab","z":"546def68.3e374","name":"devices","icon":"dashboard"}]

This the node-red output:

file

I hope this helps some people out there - please contact me if you have any questions.

</app-key></app-id>