device.isconnected issue

opbopb
edited November 2013 in Agent Code
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
«1

Comments

  • 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+"\nstaleness="+ (now-lastreceived) + "\nOK\n";
    } else {
    server.log("Device disconnected")
    resp_str = "count="+nrsent+"\nERROR disconnected\n";
    }
  • 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
  • Has there been any update to this? I've returned from the weekend to find that one of my IMPs has been off for 2 days, yet the IDE still claims that it is on. I keeping sending requests to the device (through the agent) and the agent is none the wiser. After a few minutes it does report that the agent is stopped, but the device still doggedly stays 'on'. I have refreshed the browser, logged out and back in again. No difference.
  • Hmm. The fix was pushed and we did not hear of any problems from the other customers who had previously seen the issue. Please PM me with the device ID so we can look at yours.
  • I am having connection problems starting (I think it was 1:05 AM Central time April 11, USA) in the middle of the night a few days ago. It disconnected in the middle of the night. This is either wifi out (ISP out) or maybe the imp service shut down or shut if off?

    The device would not come back without a power cycle and now it is exhibiting blink codes that are not in the documentation.

    on power up
    Amber (quick)
    Green (quick)
    Then starts RED-AMBER-RED-AMBER
    And finally locks on AMBER while continuing to run except with .isconnected not working.

    The device is sending messages to the agent and the agent log is writing them.

    However, device.isconnected() in the agent is returning false and so my web page does not load.

    I can get operation back by doing this in the agent code:

    //if (device.isconnected()){
    if (true){


    but the amber light remains on.

    { A second device is still off line from this same event and I have not messed with it }
  • update on two devices that went offline suddenly the other day (temporary isp outage or something on imp service side)

    1st imp; First exhibited odd blink codes detailed above but then suddenly after a power cycle, went green and started operating correctly.

    2nd imp; I did a power cycle one time and it did not come back up. rebuilding from the IDE only restarts the agent.

    Something is wrong somewhere, what is it?
  • 2nd imp; I did a power cycle one time and it did not come back up. rebuilding from the IDE only restarts the agent.

    Something is wrong somewhere, what is it?
    I have had that happening long ago, blinkup made it come back online again.

  • I should have mentioned; yes the last time I had this happen I did a blink-up to get it back. I raise this point because the imp should come back online without blink-up being necessary. In my case the device is closed inside of a box for safety reasons so looking at the blink codes is also not an option and there is no documented reason I should have to blink-up again.


    btw, @MikeyDK I am using wifi code that came from you. Possibly I have changed it a tiny bit but mostly it is yours. After the last occurrence of a very similar issue I added code so that UART57 would put out debug information. At some point I can hook up my logic analyzer and watch to see what the device is up to.
  • My issue seems to be back again. isdisconnected == true, even when there is data flow.
  • sorry, some of my previous responses may have taken the thread a bit off-topic. It thought my connection troubles were related but perhaps not.

    Today I again noticed .isconnected not working properly though all other aspects of this particular device are working fine. This is an imp-based tool that has been stable for a while now.


    device
    software version af0f28a - release-27.10 - Fri Dec 13 11:08:38 2013

    agent
    software version 6c94395 - jenkins-ei-named-branch-1560 - Mon Mar 10 09:05:27 2014


    returning false negative
  • Re-blinkup should never be needed. It doesn't do anything but re-populate the wifi settings fields and enrollment with the server, all of which are never written by the imp (unless your code writes them). It "resets" nothing.

    As I remember you *were* doing stuff with the SSID/password?

    Will look into isconnected() again. There's a huge server update (which should be invisible) coming soon so we're trying to avoid too much work on the current codebase. Giving device IDs that are showing the problem is helpful.
  • My device ID 23304d3643fc42ee
    (can that lead to a URL, by the way?)

    I can arrange for you to get an automatic mail.
  • Device ID does not lead to a URL, no. Device ID+plan ID can go to a URL (URL will change on every blinkup of a commercial device).

    Is that agent showing the device as offline right now then?
Sign In or Register to comment.