Note that you’d get multiple gateways in your meta data if the node’s packets were received by multiple.
You can also use the function block to return the data just as you want it. Like:
// Just a helper variable to use below
var gateways = msg.metadata.gateways;
return {
// Assuming the TTN Payload Functions decode some bytes from the node
// into a "location" in the output:
mylocation: msg.payload_fields.location,
// Some fields from the metadata
freq: msg.metadata.frequency,
cr: msg.metadata.cr,
dr: msg.metadata.dr,
// Combine RSSI and SNR of all gateways into two arrays:
rssi: gateways.map(gw => gw.rssi),
snr: gateways.map(gw => gw.snr),
// ...or: get an array with an object for each gateway:
gateways: gateways.map(gw => {
return {
location: {
lat: gw.latitude,
lng: gw.longitude
},
rssi: gw.rssi,
snr: gw.snr
}
})
};
When printing “complete msg object” in a debug node, you’d then get something like:
{
"mylocation": {
"lat": -33.8688,
"lng": 151.2092
},
"freq": 868.1,
"rssi": [-36, -45],
"snr": [9, 9],
"gateways": [
{
"id": "eui-b827ebffff5fe05c",
"location": {
"lat": 52.12345,
"lng": 4.12345
},
"rssi": -36,
"snr": 9
},
{
"id": "eui-5ccf7ff42f1970ec",
"location": {
"lat": 52.54321,
"lng": 4.54321
},
"rssi": -45,
"snr": 9
}
]
}
Or to get a msg.payload
for a Node-RED Twitter input:
var gateways = msg.metadata.gateways;
msg.payload = "Received by "
+ gateways.length
+ " gateway(s), with RSSIs "
+ gateways.map(gw => gw.rssi).join(", ")
+ " and SNRs "
+ gateways.map(gw => gw.snr).join(", ")
;
return msg;
…to get
Received by 2 gateway(s), with RSSIs -38, -44 and SNRs 9, 9