QingPing Decoder

Please include the following information, in order for us to help you as effectively as possible.

  • What product do you wish to discuss? QingPing CO2-TEMP-RH

  • What firmware version? 1.3.1

  • Computer OS? (MacOS, Linux, Windows) Windows

  • What Computer OS version? Windows 11

  • How often does the problem happen? Always

  • How can we replicate the problem? Yes

@carlrowan ,

I am using the QingPing Decoder in the TTN, but it has a problem, because I am receiving a error message: “TypeError: Cannot read property ‘toString’ of undefined or null at Decoder”

{
  "name": "as.up.data.decode.fail",
  "time": "2024-06-13T19:16:46.465691117Z",
  "identifiers": [
    {
      "device_ids": {
        "device_id": "co2-temp-rh-001",
        "application_ids": {
          "application_id": "co2-temp-rh-nasondas"
        },
        "dev_eui": "D896E0EFFF000141",
        "join_eui": "D896E0EFFF000000"
      }
    }
  ],
  "data": {
    "@type": "type.googleapis.com/ttn.lorawan.v3.ErrorDetails",
    "namespace": "pkg/scripting/javascript",
    "name": "script",
    "message_format": "{message}",
    "attributes": {
      "message": "**TypeError: Cannot read property 'toString' of undefined or null at Decoder** (<eval>:7:25(15))"
    },
    "correlation_id": "61010a4845f04a90acb2e8cec54f7da5",
    "code": 10
  },
  "correlation_ids": [
    "gs:uplink:01J09GFWH95B0N0RPRSTYJXXE1"
  ],
  "origin": "ip-10-100-7-59.eu-west-1.compute.internal",
  "context": {
    "tenant-id": "CgN0dG4="
  },
  "visibility": {
    "rights": [
      "RIGHT_APPLICATION_TRAFFIC_READ"
    ]
  },
  "unique_id": "01J09GFWR1YRJKHXYQW78VQXV3"
}

This is the Decoder that I am using in the TTN:

function Decoder(bytes, port) 
{
  var decoded = {};

  var deviceAddress = bytes[0].toString(16).toUpperCase();
  var reportCode = bytes[1].toString(16).toUpperCase();
  decoded.deviceAddress = deviceAddress;
  decoded.reportCode = reportCode;

  var dataLength = parseInt(bytes[2].toString(16), 16);
  decoded.dataLength = dataLength;

  var dataType = bytes[3].toString(16).toUpperCase();
  decoded.dataType = dataType;

  if (dataType === "1") {
    var timestampBytes = bytes.slice(4, 8);
    var timestamp = bytesToHex(timestampBytes);
    decoded.timestamp = timestamp;

    var temperatureHumidityBytes = bytes.slice(8, 11);
    var temperatureHumidityHex = bytesToHex(temperatureHumidityBytes);
    var temperatureHumidityValue = parseInt(temperatureHumidityHex, 16);
    var temperature = ((temperatureHumidityValue >> 12) - 500) / 10;
    var humidity = (temperatureHumidityValue & 0xfff) / 10;
    decoded.temperature = temperature;
    decoded.humidity = humidity;

    var co2Bytes = bytes.slice(11, 13);
    var co2Value = parseInt(bytesToHex(co2Bytes), 16);
    decoded.co2 = co2Value;

    var battery = parseInt(bytes[13].toString(16), 16);
    decoded.battery = battery;

    var versionCodeBytes = bytes.slice(14, 20);
    var versionCode = bytesToHex(versionCodeBytes);
    decoded.versionCode = versionCode;

    var crcBytes = bytes.slice(20, 22);
    var crc = bytesToHex(crcBytes);
    decoded.crc = crc;
  }
  
  return decoded;
}

function bytesToHex(bytes) 
{
  var hexArray = [];
  for (var i = 0; i < bytes.length; i++) 
  {
    var hex = (bytes[i] & 0xff).toString(16).toUpperCase();
    if (hex.length === 1) 
    {
      hex = '0' + hex;
    }
    hexArray.push(hex);
  }
  return hexArray.join('');
}

Could you help me?

Claudio

Hi @crmrosa ,

Is the error you received all the time?

Also, do you see this decoding in TTN?

Yes, here the error is:

But at the same time I can see the payload decoded:

Hi @crmrosa ,

There are more info transmitted by the Qingping sensor aside on the actual sensor reading.

Those are the other uplinks you see.

You can see the complete payload format of the transmitted uplink on this documentation from page 15.

1 Like