Skip to content

Adding a custom parser

Antoine de Chassey edited this page Sep 12, 2018 · 7 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', '%', '')

Geolocation

Payloads can contain GPS coordinates, WiFi mac address, BLE mac address & more... The platform can decode these automatically and create geoloc objets linked to receveived messages.

If the payload contains GPS positioning you have to respect the following naming for the latitude and longitude keys:

obj = {};
obj.key = 'lat';
obj.value = <your_latitude_here>;
obj.type = 'number';
obj.unit = '';
parsedData.push(obj);
obj = {};
obj.key = 'lng';
obj.value = <your_longitude_here>;
obj.type = 'number';
obj.unit = '';
parsedData.push(obj);

If the payload contains Ubiscale data for cloud GPS positioning you have to respect the following:

obj = {};
obj.key = 'ubiscale';
obj.value = <your_ubiscale_data>;
obj.type = 'string';
obj.unit = '';
parsedData.push(obj);

If the payload contains beacon positioning you have to respect the following naming for the beacon ID:

Make sure you created a beacon on the "Beacons" page first.

obj = {};
obj.key = 'beaconId';
obj.value = '<your_beacon_id_here>';
obj.type = 'string';
obj.unit = '';
parsedData.push(obj);

If the payload contains WiFi positioning you have to respect the following naming for the WiFi mac addresses and RSSI (if any):

Make sure you added the service provider environment variables first (for HERE, you need at least 2 mac addresses for privacy reasons).

obj = {};
obj.key = 'wlan_1';
obj.value = '<first_mac_address>';
obj.type = 'string';
obj.unit = '<associated_rssi_if_given>';
parsedData.push(obj);
obj = {};
obj.key = 'wlan_2';
obj.value = '<second_mac_address>';
obj.type = 'string';
obj.unit = '<associated_rssi_if_given>';
parsedData.push(obj);
etc.

Creation date

If you wish to override the creation date of the message and if the payload contains a timestamp, please follow:

obj = {};
obj.key = 'time';
obj.value = new Date(1527149661 * 1000);
obj.type = 'date';
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"
  }
]