Decrypting TTN payload messages with LoRa Device Protocol

What product/components do you use and which version/fix level are you on?

Backend: 1013.0.260
UI: 1009.0.21

Is your question related to the free trial, or to a production (customer) instance?

production

What are you trying to achieve? Please describe it in detail.

Getting data from the TTN Network into the Cumulocity Cloud

Do you get any error messages? Please provide a full error message screenshot and log file.

The connection is fine. I am following the tutorial here:

the Lora Devices (a Dragino LDS02 Door Sensor) is created. And the message ist the following:

Ttn uplink request
{ “devId”: “eui-a84041c13184f93f”, “payloadBase64Encoded”: “DFoBAAA2AAAKAA==”, “port”: 10, “appId”: “my-temperatur11”, “devEui”: “A84041C13184F93F”, “timestamp”: “2022-09-29T11:39:38.588602142Z” }

How can i build a LORA Device Protocol now?

The Base64 Payload of that Device is “DFoBAAA2AAAKAA==” in my example.
it means in HEX: “0c5a0100003600000a00” correct?

and the TTN Payload Formatter is the following:

function decodeUplink(input) {
  var port = input.fPort;
  var bytes = input.bytes;
  var value=(bytes[0]<<8 | bytes[1])&0x3FFF;
  var bat=value/1000;//Battery,units:V
  
var door_open_status=bytes[0]&0x80?1:0;//1:open,0:close
  var water_leak_status=bytes[0]&0x40?1:0;
  
  var mod=bytes[2];
  var alarm=bytes[9]&0x01;
  var data = {};
  	 switch (input.fPort) {
		 case 10:
  if(mod==1){
    var open_times=bytes[3]<<16 | bytes[4]<<8 | bytes[5];
    var open_duration=bytes[6]<<16 | bytes[7]<<8 | bytes[8];//units:min
    
      data.BAT_V=bat,
      data.MOD=mod,
      data.DOOR_OPEN_STATUS=door_open_status,
      data.DOOR_OPEN_TIMES=open_times,
      data.LAST_DOOR_OPEN_DURATION=open_duration,
     data.ALARM=alarm
    
  
}
  else if(mod==2)
  {
  var leak_times=bytes[3]<<16 | bytes[4]<<8 | bytes[5];
  var leak_duration=bytes[6]<<16 | bytes[7]<<8 | bytes[8];//units:min
  
      data.BAT_V=bat,
      data.MOD=mod,
      data.WATER_LEAK_STATUS=water_leak_status,
      data.WATER_LEAK_TIMES=leak_times,
      data.LAST_WATER_LEAK_DURATION=leak_duration
  
}
  else if(mod==3)
  
  {
      data.BAT_V=bat,
      data.MOD=mod,
      data.DOOR_OPEN_STATUS=door_open_status,
      data.WATER_LEAK_STATUS=water_leak_status,
      data.ALARM=alarm

  }

  else{
      data.BAT_V=bat,
      data.MOD=mod
  }
  return {
      data: data,
    }
	default:
    return {
      errors: ["unknown FPort"]
    }
}
}

and the result should be something like that:

{
 "ALARM": 0,
 "BAT_V": 3.162,
 "DOOR_OPEN_STATUS": 0,
 "DOOR_OPEN_TIMES": 54,
 "LAST_DOOR_OPEN_DURATION": 10,
 "MOD": 1
}

please help to make a Cumulocity Device Protocol for the LDS02

Thank you

The different payloads between Door open and Door closed are the following:
0C660100004600000000 —>>OPEN
8C660100004600000000 —>>CLOSE

it should be start bit 0 and lenght of 2? right?

now i get the value of 140 and 12? It sould be 1 and 0

how can i do that?

best Regards

12 and 140 are the decimal values of first byte (0C and 8C respectively). In binary the two are:

10001100
00001100

So I think you need to use start bit 7 and number of bits 1.

Hi Harald,

thank you very much. I found the solution. Start bit 0 and number of bits 1.
Thank you very much

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