Set DutyCycle via LoRaWAN

need a little help with my code.
I would like to send a payload to my cubecell and change the dutycycle with it.

I can see my debug print for new DutyCycle received but how can i save it to flash like setting the dutycycle with the at commands?

```
//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();
  for(uint8_t i=0;i<mcpsIndication->BufferSize;i++) {
     if (mcpsIndication->Buffer[i] == 220) { // DC for APP_TX_DUTYCYCLE; 0D BB A0  for 900000 
 (15min); 
 04 93 E0 for 300000 (5min)
       APP_TX_DUTYCYCLE = mcpsIndication->Buffer[i++]<<32|mcpsIndication->Buffer[i++] 
 <<16|mcpsIndication->Buffer[i++]<<8|mcpsIndication->Buffer[i++];
       Serial.print("  new DutyCycle received: ");
       Serial.print(APP_TX_DUTYCYCLE);
       Serial.println("ms");
      SaveDr();
    }
   }
```
 }

Here is my idea:

If you set last 2 bits of the downlink are used as the value of duty cycle (e.g. FF FF = 65535mS). After the node receives the data and stores it in the flash. Then use this data as a variable and assign it to duty cycle.

You can have a try at you side. If without success, I will update an example when we back to work.

1 Like

We are not recommended that every downlink contains information to be stored in flash. Although chip manufacturers claim that the number of flash writes exceeds 100,000 times, but the actual number is only 30,000 to 50,000 times as we tested.

i know about the restrictions of flash writes.
my code should only update the dutycycle when the first byte is DC (220 DEC) with the dutycycle calculated out of the next 4 bytes.
not every downlink will have this information only when it is needed to change the dutrycycle.

my problem is i dont know how to store the value right to get the cubecell recognize the new dutycycle.

Is this example make sense to you?

Hello friend, @wasn finally how you solve this issue ?

just curious, why not use downlink port number to define action? (save a byte of data)

also why not use a single byte payload as say a 10000ms multiplier too, reduces the downlink to one byte then - airtime is precious etc