Sleep on a rak11720

Hello,

I’m working on a node that needs to wake up every 10 seconds, read an analog signal, and only send if the right conditions are met. The problem I’m facing is that if the “RAK11720” doesn’t send, it will not properly go into sleep mode and draws around 1 mA in sleep mode. Is this a known issue, and are there any ways of fixing it?

Best regards,
Oscar

Welcome back to the forum @O.Illerup

Difficult to say without knowing you code.

Do you use api.system.lpm(1); to force low power mode?
Do you enable BLE or just leave it off?
Are you idling in the loop() and using api.system.sleep.all()
Do you use callbacks to determine whether the TX has finished before you call sleep()?
Do you use timers to wake up every 10 seconds or other methods?

This example code RUI3-Best-Practice/RUI3-RAK1901-RAK1902-Example used with a RAK1901 temperature & humidity sensor draws 28 uA when sleeping. The current is quite high because I didn’t put the sensor into low power mode. And the test was done on a WisBlock Base Board which has some parasite current consumers (I2C pull-ups, battery reading resistor divider, …)

Hey @beegee

I’m idling in the loop() and using api.system.sleep.all(). I’m not using a timer because in the timer interrupt, I can’t get a delay working. In the case you have measured, I get the same results, and the rak11720 goes into sleep and only draws around 8-10 uA after sending data. My problem is when I don’t send any data, then the rak11720 will not return to sleep properly and draws around 1 mA. Here is my loop code:

void loop() {

  if (first_loop) {
    delay(1000);
    normal_uplink_routine();
    first_loop = false;
  }
  digitalWrite(forcePin, HIGH);
  delay(10);
  force = analogRead(force_sensor);
  delay(10);
  digitalWrite(forcePin, LOW);

  D_println(force);
  D_println(activ);

  if (force > currentSettings.forceThreshold && activ == 0) {
    // Increment counter for consecutive readings over 100
    consecutiveOver++;
    // Reset counter for consecutive readings under 100
    consecutiveUnder = 0;
  } else if (force < currentSettings.forceThreshold && activ == 1){
    // Increment counter for consecutive readings under 100
    consecutiveUnder++;
    // Reset counter for consecutive readings over 100
    consecutiveOver = 0;
  }

  // Check if two consecutive readings are over 100
  if (consecutiveOver >= 2 && activ == 0) {
    lora_port = 2;
    delay(10);
    panick_uplink_routine();
    activ = true;
    // Reset counters
    consecutiveOver = 0;
    consecutiveUnder = 0;
    activ == 1;
  }

  // Check if two consecutive readings are under 100
  if (consecutiveUnder >= 2 && activ == 1) {
    lora_port = 2;
    delay(10);
    panick_uplink_routine();
    activ = true;
    // Reset counters
    consecutiveOver = 0;
    consecutiveUnder = 0;
    activ == 0;
  } 
  
  if ((elapsed = millis() - last) > currentSettings.otaaPeriod) {
    last = millis() - 1000;
    normal_uplink_routine();
  }

  delay(100);

  api.system.sleep.lora(10000);
  api.system.sleep.all(10000);
}

Guessing your xxxx_uplink_routine() calls are sending out a packet?

If you call api.system.sleep.all(10000);, before the transmission has ended, then the device will wake up again. You will have to check whether the transmission has finished before calling sleep from your loop.

The double

  api.system.sleep.lora(10000);
  api.system.sleep.all(10000);

Is not really usefull. You keep the MCU awake with the first call, only send LoRa transceiver to sleep which will not work anyway because the transmission is still ongoing.

Just find a method to get the end of transmission (we have callbacks for that) and then call sleep.

Not sure why delay() would not work in a timer callback. But usually I avoid such power wasting delays in my code wherever I can.

api.system.sleep.lora(10000); was not a part of my code, sorry, I just forgot to delete it. I need a delay to wait for a BLE scan to be done before sending the data from the scan out over LoRa. I have tried to make the call to xxxx_uplink_routine() in a timer, but the delay to wait for the BLE scan will just be skipped. This is not an issue when calling it from the main.

I can’t see why there should be an issue with sleeping before the transmission has ended, as it is when the xxxx_uplink_routine() is not called, it will not go correctly into sleep.

Her are som more data to see the problem

This cycle is repeating and it is only the first sleep periot after a send that the sleep curent is right

I really don’t know what your code is doing.

Added 50x analogRead + LEDs on and skipped every second send command and I am still getting sleep current every time.

Btw, I am using timers to start the analogRead and LED’s on and I am using delay() without problems inside the timer function.

Hey

Sorry for the late response, I have been on a skiing holiday. I will try doing some more tests on my own. Just one question:

  1. What rui3 version do you use?

Hope yo didn’t break anything :grin:

I am on RUI3 V4.1.1 staging, but for this part it would be the same with the official release RUI3 V4.1.0