I am encountering issues with the deep sleep mode with persistence of variables. The documentations states:
Note: The new Particle Photon firmware will not reset before going into stop mode so all the application variables are preserved after waking up from this mode.
However, in my test I have one variable declared that is initialized with analogRead() the first time around (if variable == 0). The sleep mode is activated with following in setup()
System.sleep(SLEEP_MODE_DEEP,60);
In 60 seconds, when the device wakes up, the value in the variable is reset to 0.
Aha! So, all this time I am assuming that whatever is in the documentation (and available on the firmware library) is implemented.
No wonder, 'cuz I just put a simple System.sleep(A7, FALLING); in setup() and blinking led in loop() and expected the loop() to never execute but the device never went to sleep. The only thing working is System.sleep(SLEEP_MODE_DEEP, long seconds) but without the register persistence.
Yes, I did. But if that were a problem, the device will still sleep and not wake up isn’t it? Anyway, I am going to wait for next version of the firmware before experimenting with advanced functions.
Maybe the difference is whether you’re using the Web IDE or local compiling, but I’ve been using the following successfully compiling locally on “latest”:
Currently after adding the latest link time optimisation(LTO) step during build phase, we have noticed that sleep is not working consistently.
If you are able to locally build and deploy via dfu-util, you can try the following make command to get sleep working.
make v=1 clean all PLATFORM_ID=6 MODULAR=n COMPILE_LTO=n program-dfu
In general Photon’s sleep should work as follows:
When you have something like below code. it uses the STM32’s low power “STANDBY” mode where after waking from deep sleep, it won’t retain the SRAM contents. It’s akin to timed RESET.
System.sleep(SLEEP_MODE_DEEP,60);
To have your SRAM variables and execution state retained on photon during sleep, you need to call STM32’s low power “STOP” mode via
System.sleep(D2, RISING, 60);//wakeup on rising edge of D2 or after 60 seconds
When I do have system.sleep command with 10 sec - the wakeup time works and the pin wakeup works. when I change the time to 60 sec the photon goes to sleep forever.
int SleepTime = 60;
void setup() {
Serial.begin(9600);
}
void loop() {
delay (5000);
Serial.print("going to sleep for "); Serial.print(SleepTime); Serial.println(" sec");
System.sleep(D0,RISING,SleepTime);
if (digitalRead(D0) == HIGH) {
Serial.println("Door is Open");
Spark.publish("Door-Open", "HOME", 60, PRIVATE);
//while (digitalRead(D0) == HIGH); // hang tight here until motion stops
}
}
Hi @itayd100 which version of the firmware are you using. If it was 0.4.3rc2 it could have been a problem as LTO was enabled due to which sleep was not working as expected.