Hi,
I’m planning to write a code that in case the imp went offline, saves readings to an external memory. I’m trying to accomplish that using server.setsendtimeoutpolicy(RETURN_ON_ERROR, WAIT_TIL_SENT, 30.0) and server.onunexpecteddisconnect(disconnectionHandler);
I have a deepsleep part of the code to save power, and it’s looping using the deepsleep.
However, when the imp searches for WiFi and doesn’t find it, it doesn’t loop, it’s like it doesn’t wake up from the deepsleep… it just freezes.
Now I simplified the code, just to get loop on the deepsleep and continue to work offline if the wifi was disconnected, and I’m using a led to confirm that is working offline… And also here, nothing happens, the led doesn’t blink constantly as it is supposed to if it goes offline when I disconnect the wifi and I have to do a hard reset to get it back to work and sometimes I need to switch imps to get it to work (I’m using imp001 on April board).
Here is my device code below. Please let me know what is it that I’m doing wrong? I’d really appreciate your help…
// This function is called if the agent link is lost
function disconnectionHandler(reason) {
flashLed();
}
function flashLed() {
// Turn the LED on (write a HIGH value)
led.write(1);
}
function flashLed2() {
// Turn the LED on (write a HIGH value)
led.write(1);
// Pause for half a second
imp.sleep(0.5);
// Turn the LED off
led.write(0);
}
function sleep(){
imp.onidle(function(){ imp.deepsleepfor(10); });
}
// PROGRAM STARTS HERE
//Do don’t terminate the program if the the wifi was disconnected
server.setsendtimeoutpolicy(RETURN_ON_ERROR, WAIT_TIL_SENT, 30.0);
// Configure the LED (on pin 2) as digital out with 0 start state
led <- hardware.pin2;
led.configure(DIGITAL_OUT, 0);
server.onunexpecteddisconnect(disconnectionHandler);
if (server.isconnected()) {server.log(“server is connected”)};
function flashLed2();
sleep();
Thanks,
Perla