Sleep 2.0 in 1.5.0 not working as expected

I tried to use the new Sleep 2.0 API.
It should work in 1.5.0, right?
I did simply this (removed all the non-sleep code to be short):

SYSTEM_THREAD(ENABLED);
SystemSleepConfiguration config;
void setup() {
    config.mode(SystemSleepMode::STOP)
          .gpio(D1, RISING)
          .duration(5s);
}
void loop() 
{
    System.sleep(config);
}

Ended up breathing white!

What is the equivalent of old System.sleep(D1, RISING, 5) in new API?
I tried ULTRA_LOW_POWER but that returned NOT_SUPPORTED.

1 Like

@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().

1 Like

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();
2 Likes

@meshmesh, interesting. @rickkas7, any thoughts on this?

@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.

2 Likes

Is there any update on this? I have been looking at the release notes and don’t see anything that says it is fixed.

1 Like

The work is progressing, but you’ll likely only see it in the LTS 2.0 release.

1 Like

Will there be any migration instructions? What to fix in code after we update to 2.0? Thank you for the work.

1 Like