RAK 3272S Custom Wake Up From Radio

Please include the following information, in order for us to help you as effectively as possible.

  • What product do you wish to discuss? RAK4631, RAK3372, RAK11200, RAK11310, RAK11722?
    AT+VER=RUI_4.0.6_RAK3272-SiP

  • What firmware are you using? (RUI3 or Arduino BSP or other IDE (e.g. STM32CubeIDE)?
    Arduino BSP

  • What firmware version? Can it be obtained with AT+VER=?

AT+VER=RUI_4.0.6_RAK3272-SiP

  • Computer OS? (MacOS, Linux, Windows)
    Linux

I am trying to create a custom wake up from radio. The aim is to sleep for approximately 10 seconds and then check for the RX messages, if the RX have messages, do the operation and sleep again. If not, sleep for 10 seconds and repeat the cycle. The problem that I faced is that I can able to put on to the sleep, and wake up after 10 seconds. If the message is received within the RX listen period, it does the operation and re-enters the sleep very well and its approximately 10uA which is awesome. However, If there are no messages in the RX listen period, callback returns +EVT:RXP2P RECEIVE TIMEOUT and after that I cannot put it to the sleep, the current is approximately 9 mA. The code block given below.

uint16_t spreading_factor = 9, bw = 2, cr = 0, tx_power = 22, preamble = 8;
double freq = 868000000;
uint8_t *payload;
bool is_finished = false;
unsigned long curr;
void recv_cb(rui_lora_p2p_recv_t data)
{
    Serial.printf("Incoming packet %d , length: %d, RSSI %d, SNR %d\n",data.Buffer[data.BufferSize-1],data.BufferSize,data.Rssi,data.Snr);
    //Do Something after receving data
}


void setup() 
{
  Serial.begin(115200);
  
  if(api.lorawan.nwm.get() != 0)
  {
    Serial.printf("Set Node deice work to P2P %s\r\n",api.lorawan.nwm.set(0) ? "Succcess":"Fail");
    api.system.reboot();
  }
  Serial.printf("Set P2P mode frequency %3.3f: %s\r\n", (freq / 1e6),api.lorawan.pfreq.set(freq) ? "Success" : "Fail");
  Serial.printf("Set P2P mode spreading factor %d: %s\r\n", spreading_factor, api.lorawan.psf.set(spreading_factor) ? "Success" : "Fail");
  Serial.printf("Set P2P mode bandwidth %d: %s\r\n", bw, api.lorawan.pbw.set(bw) ? "Success" : "Fail");
  Serial.printf("Set P2P mode code rate 4/%d: %s\r\n", (cr + 5), api.lorawan.pcr.set(cr) ? "Success" : "Fail");
  Serial.printf("Set P2P mode preamble length %d: %s\r\n", preamble, api.lorawan.ppl.set(preamble) ? "Success" : "Fail");
  Serial.printf("Set P2P mode tx power %d: %s\r\n", tx_power, api.lorawan.ptp.set(tx_power) ? "Success" : "Fail");
  //Serial.printf("P2P set Rx mode %s\r\n", api.lorawan.precv(3000) ? "Success" : "Fail");
  Serial.printf("P2P set Rx Callback Setted %s\r\n", api.lorawan.registerPRecvCallback(recv_cb) ? "Success" : "Fail");
  curr = millis();
}


void loop()
{
  if(is_finished)
  {
    Serial.printf("Sleep Ended\n");
    Serial.printf("P2P set Rx mode %s\r\n", api.lorawan.precv(2000) ? "Success" : "Fail");
    delay(3000);
    is_finished = false;
    curr = millis();  
  }
  else
  {
     api.system.sleep.all(10000);  
  }
  if(millis()-curr >10000)
  {
    is_finished = true;  
  }
  
}

Thank you in advence

Welcome to the forum @Bugra

You have a misunderstanding how LoRa P2P works.

To be able to receive packets, the RAK3172 and its internal LoRa transceiver has to be in RX mode. You cannot receive data packets while the LoRa transceiver and MCU are sleeping. You have to keep the LoRa transceiver awake.

If the LoRa transceiver is in RX mode, it consumes around 6mA and this cannot be changed.

api.lorawan.precv(2000) puts the LoRa transceiver into RX mode for only 2 seconds. Unless the packet arrives within this 2 second window, you will not get it.

Thank you for your answer beegee,

I know that I cannot get anything in the 10 second sleep duration. In the sleep duration, whether the packet is arrived or not is not important right now. The problem is that whenever I awake from the sleep and listen the LoRa RX in the RX Mode with an timeout and in that duration if anything did not comes up, it did not sleep after the duration is over (If the response is Event Timeout). In the case that the module wake up and read the data in 2 second interval it’s fine it can do the operations and sleep again. I don’t mind that in the 2 second interval consumes 6mA. After 2 second duration is finished I cannot able to put it into the sleep again if the callback returns Event Timeout.

I run your code and the device is going into sleep mode every time. No other device is sending, so RX will always end with timeout.

The 1 second looping is coming from your delay(3000) which I think is not necessary. Removing it removes the 1 second looping.

Btw, RUI3 V4.0.6 is not the latest version. You should update to V4.1.0

Thank your for your effort,
I will update and try it again thank you. I download the latest firmware from RAK Download Center but the version is V1.0.2. Where should I download the required hex file for latest RUI3. The link that I downloaded is below.
https://downloads.rakwireless.com/#LoRa/RAK3272S/Firmware/

Thank you.

Don’t download the firmware from the RAK3172 folder
Use the one from the RUI3 folder ==> https://downloads.rakwireless.com/#RUI/RUI3/Image/ ==> RAK3172-E_latest.bin

It will work on the RAK3272S

And you do not need to flash the V4.1.0 firmware if you are using Arduino BSP.
You update the BSP in Arduino to use V4.1.0 and the compiled code will be based on V4.1.0

Hello again beegee,
I did the all of the things that you suggested but I still facing the same problem. Whenever I started RX listening, power consumption increases to 7.70mA(as expected). Then whenever the timeout event occurs, it drops down to 5.5mA. I updated from the Board Manager to V4.1.0.I tried with both RAK3272 SiP, RAK3172 Evaluation Board as well. Which board and which platform did you use to get those power consumption values? Also, do you have any idea what should I try next ?

Thank you in advence

I have only RAK3172 Evaluation Boards available here.

System seems not to sleep while in RX (api.system.sleep.all(10000); is called multiple times until RX is finished.
But still getting low current after each RX cycle. Tried your exact P2P settings.

Not sure why it doesn’t work in your case.

Hi beegee,

I am now trying the same thing with the RAK11720. This time it reacts differently. Whenever I awake from the sleep, I am starting 5 second RX Mode. If the RX mode ends up with a +EVT:RXP2P RECEIVE TIMEOUT, mcu reset itself. Example is below:

uint16_t spreading_factor = 12, bw = 0, cr = 0, tx_power = 22, preamble = 8;
double freq = 868000000;
bool is_packet_arrived = false;
void recv_cb(rui_lora_p2p_recv_t data)
{
  Serial.printf("Incoming packet %d , length: %d, RSSI %d, SNR %d\n", data.Buffer[data.BufferSize - 1], data.BufferSize, data.Rssi, data.Snr);
  is_packet_arrived = true;

}

void setup()
{
  Serial.begin(115200);
  if (api.lorawan.nwm.get() != 0)
  {
    Serial.printf("Set Node deice work to P2P %s\r\n", api.lorawan.nwm.set(0) ? "Succcess" : "Fail");
    api.system.reboot();
  }
  Serial.printf("Set P2P mode frequency %3.3f: %s\r\n", (freq / 1e6), api.lorawan.pfreq.set(freq) ? "Success" : "Fail");
  Serial.printf("Set P2P mode spreading factor %d: %s\r\n", spreading_factor, api.lorawan.psf.set(spreading_factor) ? "Success" : "Fail");
  Serial.printf("Set P2P mode bandwidth %d: %s\r\n", bw, api.lorawan.pbw.set(bw) ? "Success" : "Fail");
  Serial.printf("Set P2P mode code rate 4/%d: %s\r\n", (cr + 5), api.lorawan.pcr.set(cr) ? "Success" : "Fail");
  Serial.printf("Set P2P mode preamble length %d: %s\r\n", preamble, api.lorawan.ppl.set(preamble) ? "Success" : "Fail");
  Serial.printf("Set P2P mode tx power %d: %s\r\n", tx_power, api.lorawan.ptp.set(tx_power) ? "Success" : "Fail");
  Serial.printf("P2P set Rx Callback Setted %s\r\n", api.lorawan.registerPRecvCallback(recv_cb) ? "Success" : "Fail");
  Serial.printf("TX Power on the Module %d\n", api.lorawan.ptp.get());

}
void loop()
{
    Serial.printf("Putting into the sleep\n");
    api.system.sleep.all(10000);
    Serial.printf("P2P set Rx mode %s\r\n", api.lorawan.precv(5000) ? "Success" : "Fail");
    delay(5000);
/*    if(is_packet_arrived)
    {
      Serial.printf("Doing something important\n");
      is_packet_arrived = false;
    }
  */  

}

The output is following

Set P2P mode frequency 868.000: Success

Set P2P mode spreading factor 12: Success

Set P2P mode bandwidth 0: Success

Set P2P mode code rate 4/5: Success

Set P2P mode preamble length 8: Success

Set P2P mode tx power 22: Success

P2P set Rx Callback Setted Success

TX Power on the Module 22

Current Work Mode: LoRa P2P.

Putting into the sleep

P2P set Rx mode Success

+EVT:RXP2P RECEIVE TIMEOUT

Set P2P mode frequency 868.000: Success

Set P2P mode spreading factor 12: Success

Set P2P mode bandwidth 0: Success

Set P2P mode code rate 4/5: Success

Set P2P mode preamble length 8: Success

Set P2P mode tx power 22: Success

P2P set Rx Callback Setted Success

TX Power on the Module 22

Current Work Mode: LoRa P2P.

Putting into the sleep

Thank you for your help,
Bugra

There is somewhere a run-time-problem.
If you change delay(5000); to delay(10000); in the loop it works.

It does the same behavior as before. I am using RAK11720 and the firmware version is 4.1.0. I do not understand why it is resetting.

Hi @Bugra ,

I did some verification on your issue. Resetting happen due to the this line in your callback

Serial.printf("Incoming packet %d , length: %d, RSSI %d, SNR %d\n", data.Buffer[data.BufferSize - 1], data.BufferSize, data.Rssi, data.Snr);

Remove this and the reset will be gone.

Please do note ideally callback handling must be quick and all processes must be done inside loop. For example, displaying the data received might be done in the loop. Or if you want to still print it in the callback, you might simplify the print via single array like on our RUI3 example.