function hexToBytes(hex) {
for (var bytes = [], c = 0; c < hex.length; c += 2)
bytes.push(parseInt(hex.substr(c, 2), 16));
function Decoder(request) {
if (request.path.indexOf("service") !== -1) {
var payload = JSON.parse(request.body);
value: "(" + payload.cloc.lat + "," + payload.cloc.lng + ")"
field: "LINK_QUALITY_VALUE",
value: payload.linkQuality
} else if (request.path.indexOf("data") !== -1) {
// Here you decode the current data from your sensor
// and forward it to the Datacake device.
var payload = request["GET"]; // The actual sensor data
var device = payload.id[0]; // The Sigfox device the data is coming from
// This is a helper function that converts the data string to Hex-values
var data = hexToBytes(payload.data[0]);
// Now convert the Hex-data into corresponding fields
var temperature = (data[0] << 8 | data[1]) / 10.0;
var battery = data[2] / 10.0;
// Return fields from the decoder to store in the database
// Address the device on Datacake by using Sigfox Serial