Device.isconnected() always true

Hi
For me, device.isconnected() is always true, but my device is definitely offline! What am I missing here?

This code below will return device status to web client and log to server.log, but it’s always:
2015-05-27 19:02:29 UTC+2 [Agent] The device is connected: true

`function requestHandler(request, response)
{
try
{
server.log("The device is connected: " +device.isconnected());
response.send(200, "The device is connected: " +device.isconnected());
return;
}
catch (error)
{
// Something went wrong; inform the source of the request
// ‘500’ is HTTP status code for ‘Internal Server Error’

    response.send(500, error)
}

}
http.onrequest(requestHandler)`

It can take a couple of minutes to reflect offline status: an idle TCP connection looks just like a disconnected one.

How long are you waiting?

Edit: I wrapped your code in a code tag to make it more readable (the C button above the post editor)

The imp disconnects without telling the agent (such as when it loses power), it can take a minute or two for the agent to update the internal status, as the connection state needs to be somewhat forgiving (you don’t want an ondisconnect handler firing because the imp missed a single packet… so we wait for a specified period of silence before updating the status)

It has been disconnected for 2,5 month, last time it was powered up was 11th mars 2015.

Got a deviceId or MAC address we could look at?

I can’t reproduce this with my imps :frowning:

Will this do?
Device - 232e72eb6e4936ee

I can’t see anything that would make it behave like this… a couple other questions:

Did you recently change how you check whether the device is online / offline? I believe
"Build and Run" doesn’t updated the code running in an agent of an old (not connected) device until the device connects (to prevent people from abusing agents).

For next steps - try changing your handler to return something different (maybe just have it return ‘hello world’ or something) to ensure the agent is restarting / running new code…

If that works (you get the new message), change it back to the code you have and see what happens…

I don’t think that is the case, “Build and run” will update my agent code even if device is not connected.

I now connected the device …

2015-05-28 00:06:57 UTC+2 [Device] Ready
And then disconnected it …
2015-05-28 00:09:39 UTC+2 [Status] Device disconnected
And now the result of device.isconnected() is as expected …
2015-05-28 00:09:47 UTC+2 [Agent] The device is connected: false

BUT, that is end of problem for now but we don’t know if we can trust the state of the device returned by device.isconnected(), it was obviously in a wrong state. So what can cause the state to be faulty? Maybe there is a bug in the hosting Imp server code, or it needs to be improved?