Imp is disconnected frome internet

Hello, I need help, when my imp is disconnected frome internet,need to continue to work and reconnect to the internet, my service is presenting failures.
Any help will be grateful

I’m not quite sure what you’re asking. Do you want to get the imp to continue to run when it’s no longer connected, or are you having problems getting it to reconnect?

If it’s the former, take a look at our How to run an imp offline guide, which goes into this is some detail. It may also help you with the second issue.

Hi, I want to get my imp to continue to run when it’s no longer connected and then getting it to reconnect.

You need to do two things:

  1. Set the sendtimeoutpolicy to RETURN_ON_ERROR

  2. Assign an onunexpecteddisconnect handler (this will execute when your imp unexpectedly disconnects from wifi - i.e. it will not run when you do a server.disconnect)

  3. Create your disconnect handler - this what will happen when your imp disconnects, and MUST contain code to reconnect (assuming you want your imp to reconnect).

Here’s what your code might look like (note this hasn’t been tested, and is more to demonstrate flow than anything else):

`server.setsendtimeoutpolicy(RETURN_ON_ERROR, WAIT_TIL_SENT, 30);

function offlineLoop() {
// if we’re connected, quit the offline loop
if (server.isconnected()) return;

// otherwise, reschedule and then do offline stuff
imp.wakeup(30, offlineLoop);
// offline stuff...

}

function tryConnect() {
server.connect(function(state) {
if (state == SERVER_CONNECTED) {
onConnect();
} else {
// if we didn’t connect, try again in 30 seconds
imp.wakeup(30, tryConnect);
}
}, 30);
}

function disconnectHandler(state) {
// try to connect in 30 seconds
imp.wakeup(30, tryConnect);
// offline code:
offlineLoop();
}

server.onunexpecteddisconnect(disconnectHandler);`

is working better