I’ve got an interesting problem with SLEEP_MODE_DEEP – my electron doesn’t want to wake up from deep sleep unless I specifically put a numerical value in the call to System.sleep.
But even so, if only passing in a positive number there is no difference in the binary value (irrespective of unsigned long or long or even int/unsigned int), so any difference in behaviour is absolultely unexpected and illogical.
For that reason alone an issue should be raised, since it might have an impact on other things too as long the root cause is not clear.
I did some more testing lastnight, tried to trim my code down to the least amount of code to reproduce the issue, but I was unable to reproduce the issue.
I’d also made a few other changes to my program after finding out that it worked fine with a signed value.
I’ll keep poking at deep sleep and unsigned longs, this was the second time I’d experienced this, unfortunately using the Web IDE it is really easy to get into the bad practice of not versioning your projects.
I have tried it in the setup() and in the main loop.
I have tried 10secs and 60 Secs
The code posted above is called from another function - main_check_psu_input_volts(false); - which checks the battery health and determines if it is supposed to sleep or not. The argument (false) tells us whether it was called from setup or the main loop and is in there for testing, I was wondering if you could call sleep in the setup() function and if this was the cause of the unit not waking, it’s not the problem.
Here is my entire main loop()
void loop(){
static uint32_t last_time = 0;
if (flg_send_now == true){
flg_send_now = false;
udp.sendPacket((uint8_t *) &pkt_to_send, 22, ai_ip_dest[ai_primary_dest].server_ip, ai_ip_dest[ai_primary_dest].server_udp_port);
}
if (last_time < Time.now()){
last_time = Time.now();
_uptime++; //this is not fail safe, what if we get held up in a loop for longer than 1 sec, but it will increment
if (_uptime == 1){ //things to run on the first time into the loop.
//main_check_psu_input_volts(false); //if the health is too low we will also go back to sleep in this function if we are not booting here.
}
if (_uptime %600 == 0){ //every 10 minutes
OPITO_DEBUG ("Uptime = %d secs, Memory = %d bytes", _uptime , System.freeMemory());
cloud_sync_time ();
main_check_psu_input_volts(false);
}
}
if (Particle.connected()) {
Particle.process();
}
}
I also wonder if the RTC is setting the wake interrupt, as I did have it stuck in a _wfi() at one point (without the Single Threaded Block) it never woke then either.
I’m experiencing this exact issue. I have a NO switch connected and on its fault condition it closes but the fault can last for days so I’m wanting the device to sleep again. But as I’ve found out on github issue threads, If the WKP pin is held high when a device already in deep sleep tries to wake, then the device will never wake up and require a manual reset. hehe.
As a work around I’m using a soft sleep for the fault condition which is working fine. And as I’m wanting the device to wake on a negative edge in this circumstance it is correct not to use the deep sleep mode while the fault line is held high.