UPLINK_CODEC Error - "Exception generated by quickjs"

I’ve installed Chirpstack V4 on an AWS cloud server and I’m trying to send uplink messages to Datacake. Since I wasn’t able to see the messages on datacake I was trying to identify where the problem was (I’m new both to Chirpstack and Datacake) and noticed that I was getting a message on the device Events list referring “Code: UPLINK_CODEC Level: ERROR” for each message received from the device.

  • time:“2023-09-24T23:27:00.106505317+00:00”
  • :arrow_forward:deviceInfo:{} 10 keys
    • tenantId:“52f14cd4-c6f1-4fbd-8f87-4025e1d49242”
    • tenantName:“ChirpStack”
    • applicationId:“df7032db-10f3-4332-9a32-43dc512b1122”
    • applicationName:“LoRaWAN-Field-Tester-App”
    • deviceProfileId:“7be624d9-459d-4968-a6f4-87d86ba5311e”
    • deviceProfileName:“LoRaWAN-Field-Tester-EU868”
    • deviceName:“LoRaWAN-Field-Tester-RAK10701”
    • devEui:“ac1f09fffe0cf32b”
    • deviceClassEnabled:“CLASS_A”
    • tags:{} 0 keys
  • level:“ERROR”
  • code:“UPLINK_CODEC”
  • description:“Exception generated by quickjs”
  • :arrow_forward:context:{} 1 key
    • deduplication_id:“ec75ca33-6f2d-4f89-aba7-9754da169988”

I was using a decoder supplied by the device manufacturer (RAK10701), but since it is for V3 I’ve added a wrapper function to convert to the new format used on V4, this is the full decoder code:

// v3 to v4 compatibility wrapper
function decodeUplink_old(input) {
return {
data: Decode(input.fPort, input.bytes, input.variables)
};
}

function Decode(fPort, bytes, variables) {
var decoded = {};
// avoid sending Downlink ACK to integration (Cargo)
if ((fPort === 1) || (fPort === 2)){
var lonSign = (bytes[0] >> 7) & 0x01 ? -1 : 1;
var latSign = (bytes[0] >> 6) & 0x01 ? -1 : 1;

    var encLat = ((bytes[0] & 0x3f) << 17) +
        (bytes[1] << 9) +
        (bytes[2] << 1) +
        (bytes[3] >> 7);

    var encLon = ((bytes[3] & 0x7f) << 16) +
        (bytes[4] << 8) +
        bytes[5];

    var hdop = bytes[8] / 10;
    var sats = bytes[9];

    var maxHdop = 2;
    var minSats = 5;

    if ((hdop < maxHdop) && (sats >= minSats)) {
        // Send only acceptable quality of position to mappers
        decoded.latitude = latSign * (encLat * 108 + 53) / 10000000;
        decoded.longitude = lonSign * (encLon * 215 + 107) / 10000000;
        decoded.altitude = ((bytes[6] << 8) + bytes[7]) - 1000;
        decoded.accuracy = (hdop * 5 + 5) / 10
        decoded.hdop = hdop;
        decoded.sats = sats;
    } else {
        decoded.error = "Need more GPS precision (hdop must be <" + maxHdop +
            " & sats must be >= " + minSats + ") current hdop: " + hdop + " & sats:" + sats;
        decoded.latitude = latSign * (encLat * 108 + 53) / 10000000;
        decoded.longitude = lonSign * (encLon * 215 + 107) / 10000000;
        decoded.altitude = ((bytes[6] << 8) + bytes[7]) - 1000;
        decoded.accuracy = (hdop * 5 + 5) / 10
        decoded.hdop = hdop;
        decoded.sats = sats;
    }
    return decoded;
}
return null;

Any help or tip on this issue will be a great help, including how to be able to debug this problem, in all the other reports I’ve seen about an “Exception generated by quickjs” I always saw some additional detail about the error, here I’m not seeing any additional error information.

Best regards

Fernando

I had the same issues with my codec, i had to use chatgpt and provode the codec then the errors and read the sensor datasheet turns out something else in the code from milesight was the issue and i asked gpt to isolate and only work for modbus sensors it worked, had tocuse gpt4 over 3.5 for some reason was better with js

looks like you’re trying to use a v3 codec.
something like below should work… i havent tested it though.

function decodeUplink(input) {
  let bytes = input.bytes;
  let port = input.fPort;
  let decoded = {};

  if ((port === 1) || (port === 2)){
    let lonSign = (bytes[0] >> 7) & 0x01 ? -1 : 1;
    let latSign = (bytes[0] >> 6) & 0x01 ? -1 : 1;

  let encLat = ((bytes[0] & 0x3f) << 17) +
    (bytes[1] << 9) +
    (bytes[2] << 1) +
    (bytes[3] >> 7);

  let encLon = ((bytes[3] & 0x7f) << 16) +
    (bytes[4] << 8) +
    bytes[5];

  let hdop = bytes[8] / 10;
  let sats = bytes[9];

  let maxHdop = 2;
  let minSats = 5;

  if ((hdop < maxHdop) && (sats >= minSats)) {
    // Send only acceptable quality of position to mappers
    decoded.latitude = latSign * (encLat * 108 + 53) / 10000000;
    decoded.longitude = lonSign * (encLon * 215 + 107) / 10000000;
    decoded.altitude = ((bytes[6] << 8) + bytes[7]) - 1000;
    decoded.accuracy = (hdop * 5 + 5) / 10
    decoded.hdop = hdop;
    decoded.sats = sats;
  } else {
    decoded.error = "Need more GPS precision (hdop must be <" + maxHdop +
        " & sats must be >= " + minSats + ") current hdop: " + hdop + " & sats:" + sats;
    decoded.latitude = latSign * (encLat * 108 + 53) / 10000000;
    decoded.longitude = lonSign * (encLon * 215 + 107) / 10000000;
    decoded.altitude = ((bytes[6] << 8) + bytes[7]) - 1000;
    decoded.accuracy = (hdop * 5 + 5) / 10
    decoded.hdop = hdop;
    decoded.sats = sats;
    }
  return {data: decoded};
  }
return null;
}
1 Like