Server.sleepfor() use and status

Hi All! I am new on the boards here so apologies if I missed this information somewhere. If so, feel free to redirect me.

I am using server.sleepfor() on my device. Is there an agent call similar to device.isconnected() that will return whether the device is online, sleeping or offline (in this scenario, offline would mean the device did not check in within it’s expected amount of time, aka: it is out of battery or unable to connect back to wifi). I am using device.isconnected() currently but I cannot tell whether the device is sleeping or truly offline as it returns the same for both situations.

Also, when I use server.sleepfor() the device dumps out into the server log what time it is sleeping until in the following format:

2015-04-06 13:22:09 UTC-7 [Device] sleeping until 1428352629000

It is not apparent to me how to translate “1428352629000” into a meaningful time. Can you shed some light on this? Also, is this value saved somewhere that I can manually call?

Thanks in advance for any and all information.

The value is a timestamp representing the number of seconds since 1/1/1970. Check out for more info. You can perform a simple integer calculation to work out how long it will be until the device is expected online.

However, like you said, there doesn’t seem to be an obvious way of getting that expected time from the agent. Is there a gap in the documentation? I’ve never used the function myself and I thought that there’d be some sort of handler in the agent to accept notifications but can’t find any mention of it.

Thanks for the resource on epoch time coverdrive. I appreciate it.

Does anyone else know the answer to:

Is there is a simple way to get the status of your device when using server.sleepfor() that differentiates between the device sleeping and being disconnected due to battery or wifi connection problems?


Is there a variable or other that I can call that holds the value of the time that the device is sleeping until?

Thanks again.

We had provision for this type of thing, but it didn’t make it all the way because whatever we implemented wouldn’t work for all customers.

The best way to do this may be to just send a message to the agent before you go offline (just before you call server.sleepfor, for example) which says “I’m intentionally going offline now”. You could include the time you’re going away for too, if that helps.

If the agent sees the device go offline and didn’t get one of these messages, the outage was likely unintentional.

Is it normal in to see the Agent Online when the Device is offline due using the server.sleepfor() ?

Yes, the agent stays online all the time so you can exchange data with it even when the imp is sleeping. The agent runs within the cloud service, not on the device.