This code isn’t ever actually sleeping. imp.wakeup() keeps the imp running.
If you replaced the imp.wakeup() line with:
imp.onidle(function() { server.sleepfor(10); });
…then it’d boot, log “amhere”, deep sleep for 10 seconds, then log “device reconnected”, and repeat from the deep sleep for 10 seconds (IF the connect worked - you’re not checking for success in the server.connect callback).
The AmHere log/agent.send will only be seen on a cold boot, because when it wakes after a sleep with wifi off, the server.log() and agent.send() will just return an error because there’s no connection at that point.
In this case the IMP logs a = 0 then goes to sleep for 5’
When it wakes after sleep the server.load will be executed again ?
What happens if the wifi is OFF ?
During the sleep the agent can send the STORE message ?
Is there a message buffer when IMP sleeps or when wifi is off ?
I need to know the differences with imp.wakeup(300, count); for agent messages.
Given the above device code, when the imp wakes up after its five minutes, it goes into the ACTIVE-OFFLINE state. The server.load() returns null, because the server hasn’t been contacted yet. Then count() is called; the server.log does nothing (doesn’t start a connection) because we’re in RETURN_ON_ERROR. So the code never reconnects to the server, which is probably not what you want.
In RETURN_ON_ERROR mode, an imp that wakes from deep sleep must call server.connect() in order to reconnect to the server by entering (consult the diagram) the ACTIVE-CONNECTING and then ACTIVE states.
The server.load() won’t work until and unless the connection succeeds – if that logic is essential, it should move into the server.connect completion handler. Do note that the connection handler can be called with “result” indicating a failure, not just a success.
2 and 3. There’s no built-in buffer – messages sent while the imp is offline are discarded – but you can build one yourself using the agent’s device.onconnected handler, as mentioned in this current thread: http://forums.electricimp.com/discussion/2613