Sleep the mcu and wakeup only rxcall comes

I am using RAK3172 with RUI3 v4.2.4 in LoRa P2P mode.

My goal is:

  1. Put the MCU into low-power sleep.
  2. Wake the MCU when a LoRa P2P packet is received.

I initialize LoRa with loraInit(), which calls api.lora.precv(65533), registerPRecvCallback(), and my receive callback.

Then I call:

api.system.lpm.set(1);
api.system.sleep.all();

However, sleep.all() returns immediately instead of entering sleep. The serial output is:

Sleeping…
Wakeup
Sleeping…
Wakeup

even when LoRa is disabled.

Is api.system.sleep.all() expected to work in Arduino RUI3 P2P mode?

Does LoRa P2P RX support waking the MCU from sleep, or is another API (for example sleep.lora() or another event-driven approach) required?

Welcome to the forum @bheemesh

Please check out our RUI3 example applications on Github.

RUI3-LowPower-Example shows a minimal code for lowest power consumption.

I checked the RUI3-LowPower-Example. It wakes using a periodic timer (api.system.timer).

My application is completely event-driven and has no periodic timer.

The MCU should wake only on:

  1. PIR GPIO interrupt
  2. LoRa P2P packet reception

Is api.system.sleep.all() expected to support wake-up from LoRa P2P receive (api.lora.registerPRecvCallback / api.lora.precv(65533)), or is LoRa P2P RX not a supported wake source on the RAK3172?

Then don’t use the periodic timer and instead implement the interrupt function for the PIR to trigger the sending instead.

See RUI3-RAK13011-Alarm, it uses an GPIO connected to a reed relay to trigger sending.
Set the send interval to 0 and it will only send if the interrupt occurs.

Thank you. The PIR GPIO interrupt approach is clear.

I have one more question regarding LoRa P2P.

My application has two wake-up sources:

  1. PIR GPIO interrupt
  2. Incoming LoRa P2P packet

Can api.system.sleep.all() wake the RAK3172 when a LoRa P2P packet is received (api.lora.precv(65533) + api.lora.registerPRecvCallback()), or is GPIO the only supported wake source while sleeping?

If LoRa P2P wake-up is supported, could you point me to an example?

If you register the callback for P2P RX as shown in the example code, the device will wake up on a received packet.

You can check the LoRa P2P examples.

The examples usually do not use sleep() at all they are all event driven. RUI3 will put the device into sleep whenever possible by itself, if setup with correct API calls

// Enable low power mode
api.system.lpmlvl.set(2);

api.system.lpm.set(1);