Skip to content

Adding a custom parser

Antoine de Chassey edited this page Apr 10, 2018 · 6 revisions

Let's focus on how to add your new parser in order to decode custom payloads.

You must respect a particular ontology such as the payload variable name, the geolocation structure (if any) and the result of the function you will write.

1. The payload variable name: var payload

This variable will automatically contain the Sigfox message hexadecimal frame used for your parsing, make sure to name it as above.

2. The result of the parser

This has to be an array of objects. Each object has to follow this structure:

  • key
  • value
  • type
  • unit
var obj = {};
obj.key = ; //(string) a key name
obj.value = ; //(any) a value
obj.type = ; //(string) a type (string, number, boolean)
obj.unit = ; //(string) a unit or none ('°C', '%', '')

If the payload cointains GPS coordinates you have to respecting the following naming for latitude and longitude keys:

obj = {};
obj.key = 'lat';
obj.value = 48.858093;
obj.type = 'number';
obj.unit = '';
parsedData.push(obj);
obj = {};
obj.key = 'lng';
obj.value = 2.294694;
obj.type = 'number';
obj.unit = '';
parsedData.push(obj);

Example

var payload,
  temperature,
  parsedData = [],
  obj = {};

// If byte #1 of the payload is temperature (hex to decimal)
temperature = parseInt(payload.slice(0, 2), 16);

// Store objects in parsedData array
obj = {};
obj.key = 'temperature';
obj.value = temperature;
obj.type = 'number';
obj.unit = '°C';
parsedData.push(obj);

//console.log(parsedData);
return parsedData;

Returns:

If the hexadecimal payload is '11'.

[
  {
    "key": "temperature",
    "value": 17,
    "type": "number",
    "unit": "°C"
  }
]

Clone this wiki locally