Trouble checking wifi connectivity & auto-failover

I imagine a number of people are trying this as well: I want my imps to detect loss of wifi connectivity and then run through a list of known networks to see if an alternate network is available.

I don’t seem to be seeing imp.isconnected() returning false when I kill the link.
I’m using imp.enableblinkup(true) to signal detection of link failure on the imp side.
I’ve also tried a ping/acknowledge exchange with the agent, which works when the link is there but is failing silently when I take it away. What happens to agent.send() calls if there is no connectivity? Does it block?

You need to set your timeoutpolicy (see docs) if you want sends to return (with an error) when they fail - otherwise they will block and attempt to reconnect under the hood.

imp.isconnected() should return false when the link goes down. How are you indicating this locally? Remember that without a timeoutpolicy set, every server.log will attempt to bring the link back up again.

You need to set your timeoutpolicy (see docs) if you want sends to return (with an error) when they fail - otherwise they will block and attempt to reconnect under the hood.

imp.isconnected() should return false when the link goes down. How are you indicating this locally? Remember that without a timeoutpolicy set, every server.log will attempt to bring the link back up again.

Thanks Hugo, that makes sense.

My imp is now correctly detecting loss of connectivity and changing its network parameters, sort of: it won’t connect to the new network until I power-cycle it.

Playing around a bit, the interesting behavior I can observe is that things basically work if I call imp.setwificonfiguration() with the same parameters as are currently in use. But if I change them, then the imp drops off until a cold reboot. In both cases, my onConnectedCallback is unable to send messages to the server:

function onConnectedCallback(code){
server.log(“I missed you”);
}

imp.setwificonfiguration(“name”,“pass”);
server.disconnect();
server.connect(onConnectedCallback,30);
server.log(“Are you still there?”);

… all I ever get is “Are you still there?” (The above code is run right away at boot, not dependent on loss of initial connectivity)

If it’s informative - if I just do a

server.disconnect()
server.flush()
while (!server.connected()){
server.reconnect(
}

then I get some time stuck orange/red, then it connects briefly before doing a warm reboot. If I put the imp.setwificonfiguration() command in right after the disconnect, then I only ever get red blinking until I cold-reboot - at which point the new wifi config takes effect and works.

Ah, sorry, yes. This was a late-breaking bug in releases 25 and 25.1. It’s fixed in the forthcoming release 25.2.

(Yes, we’ve changed our numbering scheme. But not by very much.)

Peter

Ok, so is there any workaround on this or sit tight?
I’m fine if the imp reboots as long as it’s found a wifi network that works beforehand. I tried to write code that does just that using the above snippet but I’m not getting consistent behavior.

Any update on this?

I’m now getting an error that several server object functions don’t exist, including server.setsendtimeoutpolicy() and server.onunexpecteddisconnect()… but get this, I only get this error one of two imps I’ve run the exact same code on. Both report the same code version, fadf935 - jenkins-ei-release-branch-719 - Wed Jul 17 10:15:31 2013

add server.isconnected() and imp.getsoftwareversion() to that list (however imp.getsoftwareversion() works in agent code)

This is functionality that exists in release 25 (of the impOS).

The imp platform has two core pieces of software (the impOS, and the cloud), and they are versioned separately. When the cloud/server updates, it affects all devices immediately (that are on that server).

When we roll out a new version of the impOS, we try to do a staggered release (for a number of reasons). During the rollout of release 25, we found a couple bugs and paused the rollout… so it’s quite possible you have some devices on release 25, and some that aren’t there yet.