Diaver
(Stas)
September 13, 2023, 4:28am
1
Hey!
I spent some time to find out how to make LPM with timers and keep board sleep rest of the time and this is an example:
uint8_t ledPin = PA8; // set your pin
uint8_t buttonPin = PA9; // set your pin
void setup()
{
Serial.begin(115200);
delay(5000);
if (!api.system.lpm.set(1))
{
Serial.println("Set low power mode is incorrect! \r\n");
return;
}
//LED
pinMode(ledPin, OUTPUT);
// BUTTON
pinMode(buttonPin, INPUT_PULLUP);
attachInterrupt(buttonPin, button_click, FALLING);
if (api.system.timer.create(RAK_TIMER_0, (RAK_TIMER_HANDLER)sensor_handler, RAK_TIMER_PERIODIC) != true)
{
Serial.printf("Creating timer failed.\r\n");
return;
}
if (api.system.timer.start(RAK_TIMER_0, 1000 * 5 , NULL) != true)
{
Serial.printf("Starting timer failed.\r\n");
return;
}
digitalWrite(ledPin, HIGH);
delay(2000);
sensor_handler(NULL);
}
void button_click()
{
sensor_handler(NULL);
}
void sensor_handler(void *)
{
Serial.println("TICK");
digitalWrite(ledPin, HIGH);
delay(50);
digitalWrite(ledPin, LOW);
}
void loop()
{
api.system.sleep.all();
api.system.scheduler.task.destroy();
}
Energy consumption:
I hope it will help someone.
1 Like
tcpipchip
(MIGUEL ALEXANDRE WISINTAINER)
September 19, 2023, 3:54pm
2
Can you implement with LoRaWAN together ?
Diaver
(Stas)
September 19, 2023, 4:10pm
3
Sorry, I do not use LoWAN, only Phy
beegee
(Bernd Giesecke)
September 20, 2023, 1:52am
4
@tcpipchip
Here is low power RUI3 example with LoRaWAN
If you wonder why there are only a few API calls for LoRaWAN in it, I setup my devices with AT commands or WisToolBox. That way I can use the same code on multiple devices without the need to change the AppEUI, DevEUI and AppKey every time.
Diaver
(Stas)
September 20, 2023, 5:56am
5
I checked your code in github and it looks almost the same like mine, except one moment: after LoRa done with sending your message you need explicitly change LoRa back to Sending mode, otherwise it will keep waiting in loop for the next incoming message and will NOT go back into LPM.
I did it like this:
void send_callback(void)
{
Serial.printf("P2P finish Rx mode %s\r\n", api.lorawan.precv(0) ? "Success" : "Fail");
}
tcpipchip
(MIGUEL ALEXANDRE WISINTAINER)
September 20, 2023, 11:49am
6
@beegee
wIch the at command to define interval ?
for example, 10 seconds ?
AT+SENDINT=00 00 00 0a ?
beegee
(Bernd Giesecke)
September 20, 2023, 12:12pm
7
simpler!
AT+SENDINT=10 sets send interval to 10 seconds.
tcpipchip
(MIGUEL ALEXANDRE WISINTAINER)
September 20, 2023, 12:18pm
8
beegee:
AT+SENDINT=10
for me i got
AT_COMMAND_NOT_FOUND
RAKwireless RUI3 Node
Setup the device with WisToolBox or AT commands before using it
RUI3 RUI_4.0.2_RAK3172-E
[SETUP] Confirmed disabled
[SETUP] Retry = 0
[SETUP] DR = 2
Current Work Mode: LoRaWAN.
beegee
(Bernd Giesecke)
September 20, 2023, 12:26pm
9
Sorry, custom AT commands need ATC instead of AT
It is ATC+SENDINT=10
tcpipchip
(MIGUEL ALEXANDRE WISINTAINER)
September 20, 2023, 12:29pm
10
beegee:
ATC+SENDINT=10
i will test
btw, in the example that you sent me, must i send a AT+JOIN ?
Looks that the user must to send…
beegee
(Bernd Giesecke)
September 20, 2023, 12:34pm
11
Once device is setup, you can use AT_JOIN=1:1, which will tell the device to automatically join on power-up or reset.
tcpipchip
(MIGUEL ALEXANDRE WISINTAINER)
September 20, 2023, 1:33pm
12
beegee:
AT_JOIN=1:1
Hey, if you use
AT+JOIN=1:1<----
And RESET, never JOIN
But, if you use
AT+JOIN=1:0<----
And RESET, and AT+JOIN=1:0, always JOIN
test there
RAK - YouTube
tcpipchip
(MIGUEL ALEXANDRE WISINTAINER)
October 3, 2023, 6:56pm
13
you sleep example looks working…
I can wake up when press a key…to ground…
// BUTTON
pinMode(Hall_Sensor, INPUT_PULLUP);
attachInterrupt(Hall_Sensor, Hydrometer_Pulse, FALLING);
But looks that is getting a lot of interrupts…
something that i have to do into Handler ?
void sensor_handler(void *)
{
MYLOG("UPLINK", "Start");
if (api.lorawan.nwm.get() == 1)
{ // Check if the node has joined the network
if (!api.lorawan.njs.get())
{
MYLOG("UPLINK", "Not joined, skip sending");
return;
}
}
Diaver
(Stas)
October 4, 2023, 12:06am
14
UPD: this option is do nothing and actually with that option device stop working after around 4-5 days.
tcpipchip
(MIGUEL ALEXANDRE WISINTAINER)
October 4, 2023, 2:44pm
15
solved about interrupt, NOISE
About your text
“UPD: this option is do nothing and actually with that option device stop working after around 4-5 days.”
What means ?
tcpipchip
(MIGUEL ALEXANDRE WISINTAINER)
November 24, 2023, 1:04pm
17
Beege
in you lowpower arduino example, why dont you never used the ATZ command ?
You mean that the RAK3172 will never stop…if stop…will trigger a watch dog ?
For example, i do a ATZ when get 3 sequences of LINKCHECK0:0:0:0:0 or when i get 3 sequences of JOIN fail…
Is really necessary i do this ATZ ?
Give me your opnion…about user experiences…
Thanks!