Device.isconnected issue

Hi there

I’ve having some issues with device.isconnected() in my agent.

function requestHandler(request, response) { server.log("is device connected? "+device.isconnected());

Gives the response:

2013-11-14 11:21:57 UTC+0: [Agent] is device connected? true

When the device is sat unpowered on the desk in front of me.

Am I misunderstanding how the isconnected() function should work?

Thanks

I suppose it takes a while before the agent “knows” the device is not connected

It’s been about 90 minutes. Plus the IDE log is pretty quick to show:

[Power State] Power state: online=>offline

Hmm, I can’t reproduce this on my end @opb - could you share your code (either here, or in a PM) to see if I can get it to happen on my imp as well.

I want to strip down my code to see if it’s something I’ve done that’s causing this. Is there a way to save a second codebase to the same imp/model, and then switch between the two. Can’t see how it would be done in the IDE…

To do this create a new model, then you can switch the device between the two models.

OK, I’m feeling really stupid now, but I can’t see where to create a new model. I can click on the existing model and change its name, but don’t seem to have any other options. Sorry!

Click in the model name and type a new name (vs picking one). This will create a new model.

Hi Hugo

Thanks for that. I can see now that when you start typing in the search box it does come up with a message saying “create a new model” - I just wasn’t typing in the search box as I thought I was in the wrong place!

Thanks again

I seem to be having a similar issue with device.isconnected() I can shut off the device, and the call still returns true. Is there documentation on how long the timeout is?

The timeout is max 9 minutes right now (ie between immediate and 9 minutes); this will improve, but that’s just where it is now.

I have a reverse issue.
I have my device monitored for uptime. part of the code is below.
Every now and then, it starts reporting it is disconnected, though it is still dumping data into xively.
Problem seems to go away after a reboot, maybe also spontaneously.

PM me for the URL of the device

if (device.isconnected()) { resp_str = "count="+nrsent+"\ staleness="+ (now-lastreceived) + "\ OK\ "; } else { server.log("Device disconnected") resp_str = "count="+nrsent+"\ ERROR disconnected\ "; }

How often are you checking device.isconnected()? The device may be disconnected at the point where this connection check happens, but the imp itself will try very hard to connect if you tell it to send data (and have default policy set).

The monitoring (Nimsoft) calls the agent, which executes the code above (amongst others), every 5 minutes.
The device is AC powered and happily reports its status every 60 seconds to Xively.
I have this documented.

Just today it was not ‘isconnected’ for a while. power cycling the device did not change the situation. ‘Build and run’ did.

I’ve been told there’s more work going on in this area; for now if you want to ensure a client is there, ping it with a device.send() and get it to send you a reply.

OK. Keep us posted.
My application is actually a data logger, so I could look at data staleness.
However, stale data would be a derived indicator, which would give limited visibility in actual failure modes.

How about timestamping new readings (either at the imp end before sending, or at the agent end when received)? This is also a good way to measure freshness.

it does. that is what my code does. See above: now and lastreceived are times.
this is a workaround, that is what it is.

Thanks for your support

BTW, this is my setup: http://www.clubcloudcomputing.com/2014/02/cloud-things/

Looks like the fix for this should be pushed early next week.

OK
Will keep an eye on it.
The disconnects are happening more often now.
Thanks