# Getting uplink metadata using Node-RED "ttn device" or "ttn message" nodes

**URL:** <https://www.thethingsnetwork.org/forum/t/getting-uplink-metadata-using-node-red-ttn-device-or-ttn-message-nodes/5096>\
**Category:** Application Development\
**Created:** [January 29, 2017, 5:13pm UTC](https://www.thethingsnetwork.org/forum/t/getting-uplink-metadata-using-node-red-ttn-device-or-ttn-message-nodes/5096 "2017-01-29T17:13:39Z")\
**Posts on this page:** 1\
**Showing post:** 11

<div class="post-metadata">

**Author:** ![arjanvanb](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/arjanvanb/32/46626_2.png) [@arjanvanb](https://www.thethingsnetwork.org/forum/u/arjanvanb)\
**Post date:** [January 31, 2017, 8:41pm UTC](https://www.thethingsnetwork.org/forum/t/getting-uplink-metadata-using-node-red-ttn-device-or-ttn-message-nodes/5096/11 "2017-01-31T20:41:20Z")

</div>

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
```

---

_[View the full topic](https://www.thethingsnetwork.org/forum/t/getting-uplink-metadata-using-node-red-ttn-device-or-ttn-message-nodes/5096)._
