How to make a payload readable?

Hi,

now my sensor node works fine and i send the following data:

00 12 78 08 01 59 89 80 03 37 60 34 11

First 4 Bytes = resistance NTC1 (127808 Ohm)
Second 4 Bytes = resistance NTC2 (159898 Ohm)
Next 3 Bytes = resistance of fluid (33760 Ohm)
Last 2 Bytes = battery voltage in mV (3411 mV)

And here i must calculate NTC resistance with function ln(x) (logarithmus naturalis) in temperature value. Is there a mathematical function for ln(x) available?
My question is how to convert this data in a human readable format or in a graphical diagram?

Can somebodey help?

Assuming you’re sure that 0x3411 decodes to decimal 3,411 (and not to decimal 13,329), then the node is using binary-coded decimal. See Is there any documentation on payload functions? for examples about conversions, including BCD.

In JavaScript, ln(x) is Math.log(x). We’d need more details about the NTCs to get a proper conversion from resistance to temperature. But the following Decoder can be used in the Payload Format in an application in TTN Console to get you started:

/**
 * Convert the array of bytes into an unsigned integer, assuming packed
 * binary-coded decimal (BCD) with an even number of nibbles, MSB, like
 * decoding 0x00127808 to decimal 127808.
 */
function bcdToUint(bytes) {
  return bytes.reduce(function(acc, byte) {
    return 100*acc + 10*(byte >> 4) + (byte & 0x0F);
  }, 0);
}

/**
 * Get a temperature given a resistance, assuming an NTC using the
 * Steinhart equation. See https://www.espruino.com/Thermistors
 */
function resistanceToTemperature(r) {
  // TODO: validate if Steinhart is okay, and adjust coefficients
  var a = 0.0012874; 
  var b = 0.00023573;
  var c = 0.000000095052;
  var w = Math.log(r);
  var temperature = 1 / (a + w*(b + c*w*w)) - 273.15;
  // Unary plus operator to cast string result of toFixed to number
  return +temperature.toFixed(1);
}

function Decoder(bytes, port) {
  var i = 0;
  var r1 = bcdToUint(bytes.slice(i, i+=4));
  var r2 = bcdToUint(bytes.slice(i, i+=4));
  var r3 = bcdToUint(bytes.slice(i, i+=3));
  var v = bcdToUint(bytes.slice(i, i+=2));

  return {
    r1: r1,
    r2: r2,
    r3: r3,
    t1: resistanceToTemperature(r1),
    t2: resistanceToTemperature(r2),
    t3: resistanceToTemperature(r3),
    v: v/1000
  };
}

If this is some off-the-shelf device, then please add some details about the brand and type. Future users might need the same answers.

For graphs, see Visualize (and push) your IOT data and LABS - Store and visualize data using InfluxDB and Grafana and many more posts on the forum and Labs.

A post was split to a new topic: How to decode CBOR in a payload format Decoder?