HTTP integration to Tago Example

in case it might help someone
I’m sending temperature and humidity from node
Cayenne LPP codec
here is the configuration in loraserver application

and payload parser in tago.io

// Add ignorable variables in this array.
const ignore_vars = ['applicationID','adr','applicationName','deviceName','devEUI','gatewayID','name',
                       'rssi','loRaSNR','location','frequency','fPort','fCnt','txInfo','rxInfo','object'];

function toTagoFormat(object_item, serie, prefix = '') {
const result = [];
  for (const key in object_item) {
    if (ignore_vars.includes(key)) continue;

    if (typeof object_item[key] == 'object') {
      result.push({
        variable: object_item[key].variable || `${prefix}${key}`,
        value: object_item[key].value,
        serie: object_item[key].serie || serie,
        metadata: object_item[key].metadata,
        location: object_item[key].location,
        unit: object_item[key].unit,
      });
    } else {
      result.push({
        variable: `${prefix}${key}`,
        value: object_item[key],
        serie,
      });
    }
  }

  return result;
}

if (!payload[0].variable) {
   //Get a unique serie for the incoming data.
   const serie = payload[0].serie || new Date().getTime();
 
  payload = toTagoFormat(payload[0], serie);
  
  const rawObject = payload.find(item => item.variable === "data");
  var rawData = rawObject.value;//.toString('utf8');  
  const buffer = Buffer.from(rawData, 'base64');
  payload.push({"variable" : "buffDisplay" , "value" : buffer.toString('hex')})
  payload.push({"variable" : "Temperature" , "value" : buffer.slice(2,4).readInt16BE() / 10 , "unit" : '°C' });
  payload.push({"variable" : "Humidity" , "value" : buffer.slice(6,7).readUInt8() / 2 , "unit" : '%' });
}

Regards
Mike

3 Likes