How to cope with loosing internet connection?

I currently have the lights in my kitchen (LED) controlled via Imp by PWM.
Having been connected recently to glass-fiber (for internet, phone and television) I am experiencing regular drop-outs of minutes or more of my internet connection, resulting in the lights in my kitchen to turn off!
Is there any way to cope with such drop-outs such that my lights do not switch off?

cheers, Moose

Yes, you should use the connection policy stuff to ensure that the imp continues to run when the internet goes down. See

The default policy will cause the imp to sleep when the connection goes down, which is what’s causing your lights to go off :slight_smile:

Thanks Hugo, lights remain on now… :-*

However, seem not to be able to re-establish connection!?

Using this to always check for connection (proudly found elsewhere in this forum):

function onConnected(status){
if (status == SERVER_CONNECTED) {
server.log("Reconnected after unexpected disconnect " + disconnectReason);

function tryToConnect(){
if (!server.isconnected()) {
server.connect(onConnected, 30);
imp.wakeup(120, tryToConnect);


imp.configure(“Kitchen-PWM-LED”, [], []);

The Imp stays in the state offline:

Sun Sep 15 2013 19:18:42 GMT+0200 (CEST): Device configured to be "Kitchen-PWM-LED"
Sun Sep 15 2013 19:28:03 GMT+0200 (CEST): Power state: online=>offline

Why doesn’t the connection get re-established?

cheers, Moose

Are you setting the policy too? If not then the policy will kick in and auto-sleep for 9 minutes.

Yes, I am:

const TIMEOUT = 10;
server.setsendtimeoutpolicy(RETURN_ON_ERROR, WAIT_TIL_SENT, TIMEOUT);

So, my question remains why the connection isn’t re-established?

If that’s your entire program, then it’s because you only re-run tryToConnect when the server isn’t connected. If it once finds the server connected, it stops rescheduling itself. What you meant, I think, is this:
function tryToConnect(){ if (!server.isconnected()) { server.connect(onConnected, 30); } imp.wakeup(120, tryToConnect); }

with the call to imp.wakeup() outside the “if”. Or is “tryToConnect” an unexpected-disconnect handler?


@Peter: :"> feel so stupid! Of course your fully right with it stopping rescheduling itself when it finds the server connected, which actually is already the case when starting the program for the first time! Btw: this was not my entire program but only the part related to reestablishing the connection once it is lost.