Location and GPS

Create a Database Field

We need to create a Database Field that stores the Location on your Datacake Device. Add a new field an select the Type "Geo Location":

Decode Location Data

In order to be able to record location data into a field on your Datacake device, you need to format the location data according to the format required by Datacake.

In the following example, we assume that your device is forwarding the location as two separate measurement values - latitude and longitude.

function Decoder(bytes, port) {
var lat = (bytes[0] << 24 | bytes[1] << 16 | bytes[2] << 8 | bytes[3]) / 1000000;
var lon = (bytes[4] << 24 | bytes[5] << 16 | bytes[6] << 8 | bytes[7]) / 1000000;
return ...
}

Datacake requires Location to be send as a joined data package.

var value = "(" + lat + "," + lon + ")"
// value = "(5.235262,21.9399536)"

In a complete example, this will look like the following:

function Decoder(bytes, port) {
​
var datacakeFields = [];
​
var lat = (bytes[0] << 24 | bytes[1] << 16 | bytes[2] << 8 | bytes[3]) / 1000000;
var lon = (bytes[4] << 24 | bytes[5] << 16 | bytes[6] << 8 | bytes[7]) / 1000000;
​
datacakeFields.push({
field: "LOCATION",
value: "(" + lat + "," + lon + ")"
});
return datacakeFields;
}

Note: The above example how to parse the bytes into Latitude and Longitude is taken from the Dragino LGT92 LoRaWAN Tracker.