Everynet JSON Payload Parser

Hi,

In my application I receive a Everyney JSON like this:

{
  "type": "uplink",
  "meta": {
    "network": "358b679dd88d47948f6e108677b4b79a",
    "packet_hash": "59a23fd7ac449263f7b56ed81830fde0",
    "application": "9405bbc000000002",
    "device_addr": "20aaaa02",
    "time": 1582039955.29871,
    "device": "9405bbc000000002",
    "packet_id": "47670fddfef3979e4f633dede36a2d02",
    "gateway": "b0fd0b7003d80000"
  },
  "params": {
    "payload": "AAAdAAAdAAAkAAAhAAARAAAL",
    "port": 2,
    "duplicate": false,
    "radio": {
      "hardware": {
        "status": 1,
        "chain": 1,
        "tmst": 3646173580,
        "snr": -2.5,
        "rssi": -108,
        "channel": 4,
        "gps": {
          "lat": -23.480249404907227,
          "lng": -46.80305862426758,
          "alt": 919
        }
      },
      "datarate": 0,
      "modulation": {
        "bandwidth": 125000,
        "type": "LORA",
        "spreading": 12,
        "coderate": "4/5"
      },
      "delay": 0.10613870620727539,
      "time": 1582039955.1759844,
      "freq": 916,
      "size": 31
    },
    "counter_up": 10,
    "lora": {
      "header": {
        "ack": false,
        "adr": true,
        "confirmed": true,
        "version": 0,
        "type": 4
      },
      "mac_commands": []
    },
    "rx_time": 1582039955.1759844,
    "encrypted_payload": "qeaEOgQcL6zqv/h0a5Yf1xrS"
  },
  "_id": 1582039954554
}

I want to show on dashboard some variables of this JSON like “payload”, “rssi”, “snr”, etc. For “payload” its working with this:

payload.find(item => item.variable === 'payload');

and this:

payload.push({ variable: 'payload', value: payload });

But the same code doesn’t work for “rssi”, “snr” and others. I realized that this variables no show on Device - Live Inspector. I can use this variables on dashboards?

Tks

Hi @roniolivi,

I’m going to convert this post on a ticket for you, so I can follow up on this situation.

Regards

Ok @alinetusi

Thank you!

Did you get any help here? I have the exact same problem.

Hi @sindre,
The SNR and RSSI should be showing up in your Live Inspector.

If not, can you send me which connector are you using, and a screenshot of your Live Inspector?

Hi @alinetusi,
Thank you for your early reply.
I am not trying to parse SNR and RSSI.
But trying to parse Cayenne LPP json format.

When I have payload:

"adr": false,
"fCnt": 620,
"fPort": 99,
"data": "AHMnhAFnAP8CaFQDcQAAABP72QSICQMxAOsgABdxBQIBdQYBAA==",
"test": 13,
"object": {
    "accelerometer": {
        "3": {
            "x": 0,
            "y": 0.019,
            "z": -1.063
        }
    },
    "analogInput": {
        "5": 3.73
    },
    "barometer": {
        "0": 1011.6
    },
    "digitalOutput": {
        "6": 0
    },
    "gpsLocation": {
        "4": {
            "altitude": 60.01,
            "latitude": 59.0641,
            "longitude": 6.0192
        }
    },
    "humiditySensor": {
        "2": 42
    },
    "temperatureSensor": {
        "1": 25.5
    }
}

Then “payload.find” works on the different variables.
But I am not able to use it on “temperatureSensor, humiditySensor” etc within the object array.
Please advice how I can catch the variables within my object array in JSON.

BR,
Sindre

Hi Sindre,
In order to help you, we need you to send us a printscreen of your Live Inspector tab of your device (when data arrives at TagoIO, it should show up there).

Also, if you have the payload parser code, please send it also so we can check what need to be fixed.

Hi @vitor,

Attached is screenshot of my “raw” data from my device.
When using TagoIO’s raw JSON to TagoIO JSON parser example it catches all the variables but not the ones inside the object array.

I need some advice how I can receive the variables within the object array.

Cheers,
Sindre

Hi Sindre,
Please, try to use this code to parse your JSON.

Basically what it does is that it goes by each of the parameters of the JSON and access each child of the parameters and then construct the TagoIO JSON.
I did just a minor changes to work with your data, as it was very to do.

function inspectFormat(object_item, serie, old_key) {

  let result = [];

  for (let key in object_item) {

    if (key === 'lng' || key === 'longitude') continue;

    else if (key === 'lat' || key === 'latitude') {

      const lng = object_item.lng || object_item.longitude;

      result.push({

        variable: 'location',

        value: object_item[key],

        location: { lat: object_item[key], lng: lng },

        serie,

      });

    } else if (typeof object_item[key] === 'object') {

      result = result.concat(inspectFormat(object_item[key], serie, old_key || key));

    } else {

      key = key.replace(/ /g, '_');

      let variable = old_key ? `${old_key}_${key}` :`${key}`;

      if (old_key && !Number.isNaN(Number(old_key))) variable = key;

      if (key && !Number.isNaN(Number(key))) variable = old_key;

      result.push({

        variable,

        value: object_item[key],

        serie,

      });

    }

  }

  return result;

}

// Payload always is an array of objects. [ { variable, value...}, {variable, value...} ...]
let my_payload = payload.find(x => x.applicationID);

if (my_payload) {

  // Get a unique serie for the incoming data.

  const serie = my_payload.fCnt || new Date().getTime();

  // Parse the my_payload to JSON format (it comes in a String format)

  let vars_to_tago = [];

  vars_to_tago.push({ variable: 'payload', value: Buffer.from(my_payload.data).toString('hex'), serie });

  delete my_payload.data;

  if (my_payload.object) {

    vars_to_tago = vars_to_tago.concat(inspectFormat(my_payload.object, serie));

    delete my_payload.object

  }

  vars_to_tago = vars_to_tago.concat(inspectFormat(my_payload, serie));

  payload = vars_to_tago;

}

Hi again @vitor,

Great!! Working like a charm, much appreciated.
Thank you :grinning:

BR,
Sindre