Khomp Device Parse

I need to separate the variable “C1” from my payload to write to the bucket. Can you help me with a “parse code”?

22:54:32:
[MQTT] Device publish
{ “topic”: “its/135954/data”, “payload”: “[{“bn”:“135954”,“bt”:1600221269,“bver”:1.3},{“n”:“C1”,“vb”:true}]”, “qos”: 1, “messageId”: 2523 }
{
“topic”: “its/135954/data”,
“payload”: “[{“bn”:“135954”,“bt”:1600221269,“bver”:1.3},{“n”:“C1”,“vb”:true}]”,
“qos”: 1,
“messageId”: 2523
}

Leandro, how did you get to solve your problem?

Hi @JimmyAntony,

Here is a payload generic for Khomp devices: 

const info = payload.find(x => x.bt);
const serie = info.bt || Number((Date.now() / 1000).toFixed(0));
const time = new Date(serie * 1000).toISOString();

const measurements = payload.filter(x => x.n);
payload = measurements.map((d) => {
  return {
    variable: String(d.n).replace(/:/, ''),
    value: d.v || d.vs || d.vb,
    serie,
    time,
    unit: d.u || null,
  };
});

const lat = payload.find(x => x.variable === 'latitude');
const lng = payload.find(x => x.variable === 'longitude');
if (lat && lng) {
  payload = payload.filter(x => !(x.variable === 'latitude' || x.variable === 'longitude'));
  payload.push({
    variable: 'location',
    value: `${lat.value}, ${lng.value}`,
    serie,
    time,
    location: {
      lat: lat.value,
      lng: lng.value,
    },
  });
}

As I said this is a generic parser, you can use it as a basis for your device model.

Thx,
Fabiano Eger