Access Gateway Metadata

Concept

You can access the global variable normalizedPayload which contains the following metadata:

{
"deveui": string, // The device's DevEUI
"port": number, // The message's port
"counter": number,
"frequency": number, // GHz
"data_rate": string, // Data rate according to https://blog.dbrgn.ch/2017/6/23/lorawan-data-rates/
"coding_rate": string,
"gateways": [
"id": string,
"datetime": date,
"channel": number,
"rssi": number,
"snr": number
]
}

This data is extracted from the LoRaWAN Network Server as being forwarded to Datacake over the Webhook. This information is normalized, meaning no matter whether you use TTN, TTI, Loriot, ChirpStack, or Wanesy, the information is always equally available and always formatted in the same way.

Raw Metadata

If you rather want to access the raw payload received from the LNS, you can do so via the global rawPayload variable.

Please note that when you access the rawPayload, the information is not normalized and the content of rawPayload looks different between different LoRaWAN Network Server!

Example Usage

In the following snippet, you find an example of how to read the Metadata from your Payload and how to bring that into your Datacake Payload Decoder section.

function Decoder(payload, port) {
// Output normalized Payload
console.log(JSON.stringify(normalizedPayload,0,4));
// Output raw payload coming from webhook of your LNS
console.log(JSON.stringify(rawPayload,0,4));
// Extract RSSI and Data-Rate from normalized Payload:
// As being "normalized" this works between all LNS:
// Including safety check so that these values really exist
var LORA_RSSI = (!!normalizedPayload.gateways && !!normalizedPayload.gateways[0] && normalizedPayload.gateways[0].rssi) || 0;
var LORA_SNR = (!!normalizedPayload.gateways && !!normalizedPayload.gateways[0] && normalizedPayload.gateways[0].snr) || 0;
var LORA_DATARATE = normalizedPayload.data_rate;
// Build up an array that can be used to forward it onto Datacake:
var decoded = [
{
field: "LORA_RSSI",
value: LORA_RSSI
},
{
field: "LORA_DATARATE",
value: LORA_DATARATE
}
];
return decoded;
}

Create corresponding fields in Database

In order to store those Metadata-Fields, you can create new Fields on your Device and have historical Data for each field that you forward and store. Here is how this looks for the above example:

​