I have data coming in from The ThingsNetwork using the TTN connectors. All works just fine but now there are more LoRa gateways around I am seeing the meta-data showing multiple sources.
[{"gtw_id":"eui-60c5a8fffe71ab20","timestamp":1177433204,
"time":"2019-05-18T05:37:18.649933Z",
"channel":7,"rssi":-125,"snr":-16,"rf_chain":1,
"latitude":-36.84942,"longitude":174.83958},
{"gtw_id":"eui-60c5a8fffe74d3a5","timestamp":1158909916,
"time":",
"channel":7,"rssi":-35,"snr":9.8,"rf_chain":1,
"latitude":-36.85412,"longitude":174.83879,"altitude":98}]
What I would like to do is only pull meta-data from my gateway (eui-60c5a8fffe74d3a5). Sometimes for example SNR is accessed as value = msg.metadata.gateways[0].snr; and sometimes it is value = msg.metadata.gateways[1].snr.
As more gateways appear it could be [2], [3] etc. How can I identify which offset in the array to access using a function that can look throughout the array, identify my gateway and from then on only pass thru the offset to my functions.
This is how I am doing it now using switches and duplicated code but I know it could be a lot tidier.
[{"id":"daa31028.bd4bf","type":"function","z":"62f2b249.fbdf4c","name":"Strip RSSI","func":"var value = msg.metadata.gateways[0].rssi;\nmsg.payload = value;\nmsg.topic = \"RSSI\";\nreturn msg;","outputs":1,"noerr":0,"x":690,"y":740,"wires":[["9c0e3bce.d88338","94808400.c69198"]]},{"id":"3c712fcf.09dae","type":"function","z":"62f2b249.fbdf4c","name":"Strip SNR","func":"var value = msg.metadata.gateways[0].snr;\nmsg.payload = value;\nmsg.topic = \"snr\";\nreturn msg;","outputs":1,"noerr":0,"x":680,"y":660,"wires":[["eaa62bef.7c1708","ac95c00c.2a26a"]]},{"id":"97c7af2d.7ccd2","type":"switch","z":"62f2b249.fbdf4c","name":"switch1","property":"metadata.gateways[0].gtw_id","propertyType":"msg","rules":[{"t":"eq","v":"eui-60c5a8fffe74d3a5","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":440,"y":700,"wires":[["7fcea8f9.1007a8","3c712fcf.09dae","daa31028.bd4bf"]]},{"id":"a19032a9.b784c","type":"switch","z":"62f2b249.fbdf4c","name":"switch3","property":"metadata.gateways[1].gtw_id","propertyType":"msg","rules":[{"t":"eq","v":"eui-60c5a8fffe74d3a5","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":440,"y":820,"wires":[["d007c91e.c0bcb8","fb9be853.7e5528","4b2b94bd.711ddc"]]},{"id":"4b2b94bd.711ddc","type":"function","z":"62f2b249.fbdf4c","name":"Strip RSSI","func":"var value = msg.metadata.gateways[1].rssi;\nmsg.payload = value;\nmsg.topic = \"RSSI\";\nreturn msg;","outputs":1,"noerr":0,"x":690,"y":860,"wires":[["9c0e3bce.d88338"]]},{"id":"fb9be853.7e5528","type":"function","z":"62f2b249.fbdf4c","name":"Strip SNR","func":"var value = msg.metadata.gateways[1].snr;\nmsg.payload = value;\nmsg.topic = \"snr\";\nreturn msg;","outputs":1,"noerr":0,"x":680,"y":800,"wires":[["eaa62bef.7c1708"]]}]