I can’t fully understand what’s being said in this sentence:
On the imp, server.load() only works if the server has already been contacted: i.e., if the server hasn't yet been contacted -- if the imp has only ever been in the ACTIVE-OFFLINE state since the last wake-up -- server.load() will return null.
which is in this page.
Can anyone explain this to me in more detail?
The imp supports a very-low-power “deep sleep” mode, which is entered by calling server.sleepfor() or one of the closely-related functions. When you do that, the imp goes to sleep, and then wakes up some time later. When it wakes up again, it’s forgotten the contents of server.load(); it only gets told them again the first time it connects to the server. But, on a wake from deep sleep, it doesn’t contact the server by default: it does so only when it first needs to, such as when the code does server.log() or agent.send().
So, in code that runs after a deep sleep but before the server is next contacted, server.load() will return null.
Thank you for the answer Peter.
So, is there a way to store data on the device and still have after power-off, without having to send it to the server (something like the nv table but with the capability to resist after power-off) ?
No, there isn’t; nothing on the device survives power-off. That was the whole idea behind server.load().
The nv table does survive deep sleep, though.
Ok. If so, I might have some problems when the internet is not reachable (no wi-fi signal) and at the same time the Imp turns off (runs out of battery, for instance).
What about the server? I’ve read some threads about the agent being restarted at some point. In which situations does that happen? Can I provoque agent restarts for testing purposes? When it does restart, the data saved using server.save() will survive? (sorry for the long questions’ chain).
server.save() and server.load() will survive an agent restart.
Thanks also for the heads-up, joaodiogocosta. I will update the server.load() page.