Imp last online and next online times

There are various functions, such as server.expectonlineat(…) server.expectonlinein(…), etc.

I would like to be able to find out from the agent side both when the Imp was last seen by the agent, and when it is next expected to be seen. I can’t find the relevant functions in the current API. Is this possible with the current API? If not, is it planned for a future release?

The purpose for this is that if the Imp is not currently online when an http request comes in, it would be nice to be able to either cache the request until the Imp will be online (if it is quite soon), or respond telling the caller when the Imp is next expected online.


I suppose you can build such a function yourself

You could! I’m part way there.

The bit I need in order to do so is the bit that prints out lines such as…

sleeping until 1373130797000

When calling server.sleepfor(…). This is the bit that knows when to expect the Imp to come online again. Really I just need to be able to access this number. My tests have shown that it differs slightly from the number reported by time() on the Imp when calling server.sleepfor(…).


It should only differ by a few seconds. Since it takes an unknown time to connect anyway, this difference would not be significant.

The point is that the agent gets informed of when to expect the Imp online again and it would be useful to be able to access this on the agent side.

What you’re suggesting would necessitate replicating the message that already goes from the Imp to the agent with another message saying pretty much the same thing and where the times will vary slightly.

Since there’s already a message from the Imp telling the agent when it expects to come online again it would be useful to access it, rather than re-inventing the wheel.


This has been partially implemented; you’ll get a table passed in to your device.disconnect callback with details. Server-side isn’t there yet though but coming soon.