Can't server.connect() after deep sleep

Hey guys,

This is giving me a big headache: when I use RETURN_ON_ERROR and wake after after a deep sleep using server.sleepuntil() or imp.deepsleepuntil() I end up not able to connect again to the server.

I do something like this

`function poll() { server.connect(function(result) { if (result == SERVER_CONNECTED) "do something"; }, 30);
// poll some sensor

}

poll();

// wake up every in the exact 0 seconds of the next minute
imp.onidle(function() {
imp.deepsleepuntil(date(time(), ‘u’).hour, date(time(), ‘u’).min + 1, 0 );
});`

Is this wrong? I noticed that the device doesn’t wait for the server.connect() callback to run and enters immediately in deep sleep. Is that it? How can I solve this?

Thanks in advance,

The imp counts as “idle” if nothing needs doing now. The fact you’ve set a connection callback for some time in the future, doesn’t stop it counting as “idle” and running the onidle handler. So yes, it doesn’t wait for the server.connect() callback to run. You should move the deep sleep into the server.connect() callback, if that’s when you want it to happen.

Peter

Thanks, I can do that. I’ll try it later and give some feedback.

@peter, with that approach, what is the best way to use server.expectonlineat() ? Right before imp.deepsleepuntil() ?

If you’re interested in the server keeping track of whether the imp is deliberately or accidentally disconnected, then yes you should user server.expectonlineat() just before calling imp.deepsleepuntil(). Although, if you’re passing the same time to both of them (i.e., you’re going to reconnect every time you wake up), then you can use server.sleepuntil() instead which combines the effect of both calls.

Peter

Thanks @peter