Downlink Data Decryption

Hi All,

I am using the Downlink LoRaWAN example and wondering how the downlink data is decrypted.

Here is the handler code

//downlink data handle function example
void downLinkDataHandle(McpsIndication_t *mcpsIndication)
{
  Serial.printf("+REV DATA:%s,RXSIZE %d,PORT %d\r\n",mcpsIndication->RxSlot?"RXWIN2":"RXWIN1",mcpsIndication->BufferSize,mcpsIndication->Port);
  Serial.print("+REV DATA:");
  for(uint8_t i=0;i<mcpsIndication->BufferSize;i++)
  {
    Serial.printf("%02X",mcpsIndication->Buffer[i]);
  }
  Serial.println();
  uint32_t color=mcpsIndication->Buffer[0]<<16|mcpsIndication->Buffer[1]<<8|mcpsIndication->Buffer[2];
#if(LoraWan_RGB==1)
  Serial.print("Color:");Serial.println(color);
  turnOnRGB(color,5000);
  turnOffRGB();
#endif
}

So I see it decrypts the value color - for example if I send from TTN
bytes 01 - then color = 127651
bytes 02 - then color = 193187
bytes 03 - then color = 258723

etc

So what encrytion is that -

I would like to be able to use a downlink to change my Tx interval

regards
Paul

This little code will decrypt the downlink:
DC for APP_TX_DUTYCYCLE; 0D BB A0 for 900000 (15min); 04 93 E0 for 300000 (5min)

you can send DC 0D BB A0 for 15min or DC 04 93 E0 for 5 min.
The code below will only print the received dutycycle to the serial terminal and not store it and use it.

void DownLinkDataHandle(McpsIndication_t *mcpsIndication)
{
  Serial.printf("+REV DATA:%s,RXSIZE %d,PORT %d\r\n",mcpsIndication->RxSlot?"RXWIN2":"RXWIN1",mcpsIndication->BufferSize,mcpsIndication->Port);
  Serial.print("+REV DATA:");
  for(uint8_t i=0;i<mcpsIndication->BufferSize;i++) {
    Serial.printf("%02X ",mcpsIndication->Buffer[i]);
  }
  Serial.println();
  uint8_t i=0;
  if (mcpsIndication->Buffer[i] == 220) { // DC for APP_TX_DUTYCYCLE; 0D BB A0  for 900000 (15min); 04 93 E0 for 300000 (5min)
    appTxDutyCycle = mcpsIndication->Buffer[i++]<<32|mcpsIndication->Buffer[i++]<<16|mcpsIndication->Buffer[i++]<<8|mcpsIndication->Buffer[i++];
    Serial.print("  new DutyCycle received: ");
    Serial.print(appTxDutyCycle);
    Serial.println("ms");
    saveDr();
  }
}

Thanks very much, I’ll give it a try.

What method is used to encrypt these figures

I gave this a go using the example provided LoRaWan_downlinkdatahandle.ino and replaced the existing data handle code with yours above.

In the Serial Monitor i get this response, but it never seems to get through to the Serial.print of new duty cycle received.

Event : Rx Done
receive data: rssi = -13, snr = 13, datarate = 13
+REV DATA:RXWIN1,RXSIZE 3,PORT 2
+REV DATA:0493E0

I suspect there may be an issue with this line

if (mcpsIndication->Buffer[i] == 220)

Your rev data is wrong.
My code looks for the starting byte DC.
You have to send DC and then tje bytes for the new dutycyle.
DC 9D BB A0 for 15min for example.

OK thanks I’ll give that a try (didn’t realise it was part of the downlink payload)

Sorry still no difference

Can you pick what I may be doing incorrectly from this

receive data: rssi = -6, snr = 13, datarate = 13
+REV DATA:RXWIN1,RXSIZE 4,PORT 2
+REV DATA:DC0493E0

For anybody else looking here, I have worked out a downlink that changes the duty cycle for 10 minutes for every byte sent i.e. 01 = 10 min, 02 = 20 min etc etc, which provides me with all the functionality I need for now

//downlink data handle function
void downLinkDataHandle(McpsIndication_t *mcpsIndication)
{
  Serial.printf("+REV DATA:%s,RXSIZE %d,PORT %d\r\n",mcpsIndication->RxSlot?"RXWIN2":"RXWIN1",mcpsIndication->BufferSize,mcpsIndication->Port);
  Serial.print("+REV DATA:");
  for(uint8_t i=0;i<mcpsIndication->BufferSize;i++) {
    Serial.printf("%02X",mcpsIndication->Buffer[i]);
  }
  Serial.println();

  if (mcpsIndication->BufferSize == 1) {
    Serial.println("Check 1 Byte Message");
    appTxDutyCycle = (mcpsIndication->Buffer[0])*600000;
    Serial.print("Changing TX Interval to: ");Serial.print(appTxDutyCycle/60000);Serial.println(" mins");
  }
}