Need some help with a Codec for Wisblock device

I’m trying to decode some data from a Wisblock sketch for environment monitoring. The code I have for the Codec is as follows:

function decodeUplink(fPort, bytes) {
  var data = {};

  if (fPort === 2) {
    // Decode temperature
    var temp = bytes[0] << 8 | bytes[1];
    data.temperature = temp / 100.0;

    // Decode humidity
    var hum = bytes[2] << 8 | bytes[3];
    data.humidity = hum / 100.0;

    // Decode pressure
    var pres = bytes[4] << 8 | bytes[5];
    data.pressure = pres / 100.0;

    // Decode gas resistance
    var gas = bytes[6] << 24 | bytes[7] << 16 | bytes[8] << 8 | bytes[9];
    data.gasResistance = gas;
  }

  return data;
}

The .ino file can be found here:

No matter what I do, I always get the error: "“decodeUplink did not return ‘data’” in the event logs. Not sure how to troubleshoot this?

Try the below
return {data: data}

Thanks, that appears to have cleared the error. There is now an additional entry in the JSON in the Event view. However, the line that I believe should hold the data says:

  • data:“AQfmFWYAAXMiAABEfg==”
  • object:{} 0 keys

You need to put your codec into Chirpstack to decode data into object (json).

Check codec in device profile.

My codec Javascript is in the device profile. The more I look at this, the more it seems the payload from the end device is corrupted somehow.

If I’m understanding the system correctly, the data coming over the LoRa network lands in the Events list, from where you can see the encoded data. For example

data:"AQfwE4sAAXNUAABYaA=="

From there, you should be able to decode that data into Hex. But that’s where things go weird. The above data, when coverted to hex, comes up as:

að‹sTXh

When looking at the serial monitor of the device, the data is being echoed to the console and all looks fine.

15:35:37.549 -> Sending frame now...
15:35:37.966 -> result: Tem:20.34C Hum:50.03% Pres:950.60KPa Gas:22608Ohms
15:35:37.966 -> lmh_send ok count 2852
15:35:57.570 -> Sending frame now...
15:35:57.941 -> result: Tem:20.34C Hum:49.92% Pres:950.60KPa Gas:22560Ohms
15:35:57.941 -> lmh_send ok count 2853
15:36:17.592 -> Sending frame now...
15:36:17.963 -> result: Tem:20.35C Hum:49.95% Pres:950.62KPa Gas:22560Ohms
15:36:17.963 -> lmh_send ok count 2854

You may check if the codec for your device is here.

This is a sample codec.

// Decode uplink function.
//
// Input is an object with the following fields:
// - bytes = Byte array containing the uplink payload, e.g. [255, 230, 255, 0]
// - fPort = Uplink fPort.
// - variables = Object containing the configured device variables.
//
// Output must be an object with the following fields:
// - data = Object representing the decoded payload.
function decodeUplink(input) {
var bytes = input.bytes;

var BatV = (bytes[0] << 8 | bytes[1]) / 1000 + 0.277;
var PayVER = bytes[2];
// If AT+DATAUP=1, PayloadCount=1 byte, payload#=1 byte
var Temp = (bytes[3] << 8 | bytes[4]) / 10;
var Humid = (bytes[5] << 8 | bytes[6]) / 10;

return {“data”: {“BatV”:BatV, “PayVER”:PayVER, “Temp”:Temp, “Humid”:Humid}};
}

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.