TTN and Cayenne: how to do calculations or how to return data

I just got the Dragino LDDS75 LoRaWAN Distance Detection Sensor and connected it successully to TTN, configured the payload decoder and can receive the sensors readings in Cayenne.

What I want to achieve with the distance sensor is to monitor the amount of fluid level in a tank. What I get is a distance reading to the surface of the fluid. So I need to do some calculations:

($TANK_HEIGHT - $SENSOR_READING) x CONSTANT

to get the amount of fluid in the tank.

Where is the typical place to do such a thing? Should I modify the Payload Decoder or is there any other place to do this kind of stuff?

I thought, i could do some calculations in the payload decoder and return some aditional data from the payload decoder like this

function Decoder(bytes, port) {
  // Decode an uplink message from a buffer
  // (array) of bytes to an object of fields.
  var value=(bytes[0]<<8 | bytes[1]) & 0x3FFF;
  var batV=value/1000;//Battery,units:V
   
  value=bytes[2]<<8 | bytes[3];
  var distance=(value);//distance,units:mm
  //var distance=((1000-value)*7)+" mm";//distance,units:mm
  if(value===0)
    distance = "No Sensor";
  else if(value<280)
    distance = "Invalid Reading";
    
  return {
       Bat:batV +" V",
       Temp:20 +" c", 
       prox:distance +" cm",
       Distance:distance +" mm", 
       tl: 50 +" null", 
       liquid: 700 +" l"
  };
}

but the additional (bogus) data did not appear in Cayenne. Any ideas what I could do instead? Any hints you can give me?

Thank you very much!

you cannot do something like this as codec for Dragino LDDS75 LoRaWAN Distance Detection Sensor is meant to accept only certain payload to show the particular widgets.

1 Like

Thank your for your reply!

Does cayenne receive the “raw” data direct from the device without any need to install a packet decoder?

Anyway: being able to do (simple) calculations like this would be on my wish list.

Your help is appreciated very much!

1 Like
1 Like

Be very nice to be able to do something with the data - the ldds75 is a great very affordable sensor from what I can see but without being able to “process” the data in cayenne to show a tank level instead of a distance its use is limited somewhat. There needs to be the ability to “post process” in TTN or Cayenne to get the data to the required format

@tim2 we have cayenneLPP format for the same. You can do all the needed processing on the device itself and then send it to cayenne.