@meshmesh, since the only thing is loop() is the sleep command, the device will go to sleep, wake then go to sleep again and so on. I’m surprised you even get breathing white! To test, add some code to flip the D7 LED after each sleep and add a millis() delay to waste some time before ending loop().
I should have mentioned that this was on purpose shortened to show just the sleep calls.
The real test program is of course longer, see below.
If I use the old sleep api, it works as expected, with new, it ends up breathing white.
#define __SLEEP_2_0__
SYSTEM_THREAD(ENABLED);
SystemSleepConfiguration config;
SystemSleepResult result;
unsigned long endTime = 0;
void setup() {
config.mode(SystemSleepMode::STOP)
.gpio(D1, RISING)
.duration(5s);
}
enum State { wait, sleeping, publishResult } state = sleeping;
void loop()
{
switch (state){
case wait:{
if (millis() > endTime){
state = sleeping;
}
}
break;
case sleeping:{
#ifdef __SLEEP_2_0__
result = System.sleep(config);
#else
result = System.sleep(D2, RISING, 10);
#endif
state = publishResult;
}
break;
case publishResult:{
if (Particle.connected()){
if (result.error() == SYSTEM_ERROR_NONE){
Particle.publish("test", "OK", PRIVATE);
}
else {
Particle.publish("test", String(result.error()).c_str(), PRIVATE);
}
state = wait;
endTime = millis() + 10000UL;
}
}
break;
}
}
BTW, tried HIBERNATE mode too, it returned also NOT_SUPPORTED.
But adding connect after sleep worked.
It seems that the new sleep does not restore the connection like the old one, even when system mode is automatic. That is why it breathed white.
result = System.sleep(config);
Particle.connect();
@meshmesh
I’m engaging engineering on this issue directly, since sleep 2.0 is not working as expected.
I will be able to update you on the path forward on Thursday.