Access Gateway Metadata

Concept

You can access the global variable normalizedPayload which contains the following metadata:
1
{
2
"deveui": string, // The device's DevEUI
3
"port": number, // The message's port
4
"counter": number,
5
"frequency": number, // GHz
6
"data_rate": string, // Data rate according to https://blog.dbrgn.ch/2017/6/23/lorawan-data-rates/
7
"coding_rate": string,
8
"gateways": [
9
"id": string,
10
"datetime": date,
11
"channel": number,
12
"rssi": number,
13
"snr": number
14
]
15
}
Copied!
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.
1
function Decoder(payload, port) {
2
3
// Output normalized Payload
4
console.log(JSON.stringify(normalizedPayload,0,4));
5
6
// Output raw payload coming from webhook of your LNS
7
console.log(JSON.stringify(rawPayload,0,4));
8
9
// Extract RSSI and Data-Rate from normalized Payload:
10
// As being "normalized" this works between all LNS:
11
// Including safety check so that these values really exist
12
var LORA_RSSI = (!!normalizedPayload.gateways && !!normalizedPayload.gateways[0] && normalizedPayload.gateways[0].rssi) || 0;
13
var LORA_SNR = (!!normalizedPayload.gateways && !!normalizedPayload.gateways[0] && normalizedPayload.gateways[0].snr) || 0;
14
var LORA_DATARATE = normalizedPayload.data_rate;
15
16
// Build up an array that can be used to forward it onto Datacake:
17
var decoded = [
18
{
19
field: "LORA_RSSI",
20
value: LORA_RSSI
21
},
22
{
23
field: "LORA_DATARATE",
24
value: LORA_DATARATE
25
}
26
];
27
28
return decoded;
29
}
Copied!

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:

Last modified 1yr ago