RAK3272 - waking from deep sleep

Hi,

device RAK3272LP-Sip cannot wake up after several seconds - after first sleep :confused:
AT+VER=RUI_4.2.1_RAK3272-SiP
flash/updated RAK3272LP-SiP_latest_final.hex
Please, is there any example code, pls?

Sketch: arduino-IDE, i. e. ino
Board: WisDuo RAK3272LP-SiP

Correctly connected to GW
and registered in *.thethings.industries

AT+VER=RUI_4.2.1_RAK3272-SiP
Europe 863-870 MHz (SF9 for RX2)
LoRaWAN version - LoRaWAN Specification 1.0.3

Serial output
10:53:45.193 → RAK3172 started or woke up!
10:53:45.193 → ------------------------------------------------------
10:53:45.193 → First boot, initializing LoRaWAN…
10:53:45.193 → Joining LoRaWAN network…
10:53:45.262 → Wait for LoRaWAN join…+EVT:JOINED
10:53:50.378 → Join status: 0
10:53:55.276 → Join success!
10:53:55.276 → Data Packet:
10:53:55.276 → 0x48 0x65 0x6C 0x6C 0x6F
10:53:55.276 → Sending is requested
10:53:55.276 → Current Work Mode: LoRaWAN.
10:54:00.381 → Successfully sent
10:54:00.381 → Going to deep sleep for 15000 ms…
10:54:00.571 → +EVT:TX_DONE
… end of serial communication

thx

Welcome to the forum @cygnet

Without seeing your code it is quite difficult to say anything.

We have plenty of examples in the RUI3 BSP itself and some more advanced examples in our RUI3-Best-Practice.

For the RUI3-Best-Practice examples, you will not see a sleep command. When enabling low power mode, the device will always sleep if there is no event. Events in the examples are triggered with timers or interrupts.

Bernd, OK & thanks. I’ll walk through.

Below code (sorry) - does that make sense? Or am I completely off base?
note: OTAA_DEVEUI, OTAA_APPEUI, OTAA_APPKEY deleted for this topic…

#define DEEPSLEEP_PERIOD_MS (15000)

#define OTAA_BAND RAK_REGION_EU868
uint8_t OTAA_DEVEUI = {};
uint8_t OTAA_APPEUI = {};
uint8_t OTAA_APPKEY = {};

uint8_t collected_data[64] = {0};

void recvCallback(SERVICE_LORA_RECEIVE_T *data) {
if (data->BufferSize > 0) {
Serial.println(“Something received!”);
for (int i = 0; i < data->BufferSize; i++) {
Serial.printf(“%x”, data->Buffer[i]);
}
Serial.print(“\r\n”);
}
}

void joinCallback(int32_t status) {
Serial.printf(“Join status: %d\r\n”, status);
}

void sendCallback(int32_t status) {
if (status == RAK_LORAMAC_STATUS_OK) {
Serial.println(“Successfully sent”);
} else {
Serial.println(“Sending failed”);
}
Serial.printf(“Going to deep sleep for %u ms…\r\n”, DEEPSLEEP_PERIOD_MS);
api.system.sleep.all(DEEPSLEEP_PERIOD_MS);
}

void uplink_routine() {
const char *message = “Hello”;
uint8_t data_len = strlen(message);
memcpy(collected_data, message, data_len);
Serial.println(“Data Packet:”);
for (int i = 0; i < data_len; i++) {
Serial.printf(“0x%02X “, collected_data[i]);
}
Serial.println(””);
if (api.lorawan.send(data_len, collected_data, 2, false, 1)) {
Serial.println(“Sending is requested”);
} else {
Serial.println(“Sending failed”);
Serial.printf(“Sending failed, going to deep sleep for %u ms…\r\n”, DEEPSLEEP_PERIOD_MS);
api.system.sleep.all(DEEPSLEEP_PERIOD_MS);
}
}

void setup() {
Serial.begin(115200);
delay(2000);
Serial.println(“------------------------------------------------------”);
Serial.println(“RAK3172 started or woke up!”);
Serial.println(“------------------------------------------------------”);
api.lorawan.registerRecvCallback(recvCallback);
api.lorawan.registerJoinCallback(joinCallback);
api.lorawan.registerSendCallback(sendCallback);
if (api.lorawan.njs.get() == 0) {
Serial.println(“First boot, initializing LoRaWAN…”);
if (!api.lorawan.appeui.set(OTAA_APPEUI, 8)) {
Serial.println(“LoRaWan OTAA - set application EUI is incorrect!”);
return;
}
if (!api.lorawan.appkey.set(OTAA_APPKEY, 16)) {
Serial.println(“LoRaWan OTAA - set application key is incorrect!”);
return;
}
if (!api.lorawan.deui.set(OTAA_DEVEUI, 8)) {
Serial.println(“LoRaWan OTAA - set device EUI is incorrect!”);
return;
}
if (!api.lorawan.band.set(OTAA_BAND)) {
Serial.println(“LoRaWan OTAA - set band is incorrect!”);
return;
}
if (!api.lorawan.deviceClass.set(RAK_LORA_CLASS_A)) {
Serial.println(“LoRaWan OTAA - set device class is incorrect!”);
return;
}
if (!api.lorawan.njm.set(RAK_LORA_OTAA)) {
Serial.println(“LoRaWan OTAA - set network join mode is incorrect!”);
return;
}
Serial.println(“Joining LoRaWAN network…”);
if (!api.lorawan.join()) {
Serial.println(“LoRaWan OTAA - join fail!”);
return;
}
time_t join_start_time = millis();
while (api.lorawan.njs.get() == 0) {
Serial.print(“Wait for LoRaWAN join…”);
delay(10000);
if (millis() - join_start_time > 120000) {
Serial.println(“Join failed, rebooting.”);
api.system.reboot();
}
}
Serial.println(“Join success!”);
} else {
Serial.println(“Device woke up and is already joined.”);
}
if (api.lorawan.njs.get() == 1) {
uplink_routine();
} else {
Serial.println(“Not joined, skipping uplink.”);
Serial.printf(“Not joined, going to deep sleep for %u ms…\r\n”, DEEPSLEEP_PERIOD_MS);
api.system.sleep.all(DEEPSLEEP_PERIOD_MS);
}
}

void loop() {}

I think you have a misunderstanding with the api.system.sleep.all() function.

It puts the device into sleep mode. But when it wakes up, it continues the code from where you put it into sleep. It doesn’t restart the setup() function.

So in your case, after it wakes up, it does just run an empty loop.

So, if you want to send a packet every 15 seconds, you better use a timer and initiate sending every 15 seconds.
There is not really a need to use api.system.sleep.all(xxxx), it is better to use api.system.lpm.set(1)

	// Enable low power mode
#if defined(_VARIANT_RAK3172_) || defined(_VARIANT_RAK3172_SIP_)
	/// \todo REQUIRES BSP VERSION 4.2.1
	api.system.lpmlvl.set(2);
#endif
	api.system.lpm.set(1);

Once enabled, the MCU will go into lowest power sleep mode until an event happens.

Maybe have a look into RUI3-LowPower-Example.ino.

The loop is forcing immediate sleep mode (forever). Sending is initiated with a timer and receiving is automatic and calls the RX callback if a data packet arrived.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.