I think now I’m having the wifi on/off working properly. But still have the problem to bypass the normal boot-up process and go straight to squirrel running after the 60 seconds of blinkup/connect. I’ll try to provide the code that I’m running:
After reading this offline guide, it sais:
“If the imp is set to RETURN_ON_ERROR, however, it will continue to run its code. Because disconnection was deliberate, any callback function registered using the server.onunexpecteddisconnect() method will not be called.”
An example code is provided below, and I’m copying that to accomplish deliberate disconnection and run my startup script which will check for timer interrupts and re-trigger or re-assign depending on their state and time since last run:
`function disconnection_handler(reason)
{
if (reason != SERVER_CONNECTED) {
DISCONNECTED <- true;
MAIN_INTERVAL <- 1.0;
} else {
DISCONNECTED <- false;
MAIN_INTERVAL <- 60;
}
}
server.setsendtimeoutpolicy(RETURN_ON_ERROR, WAIT_TIL_SENT, 30);
server.onunexpecteddisconnect(disconnection_handler);
// according to the example i’m disabling blink-yp
imp.enableblinkup(false);
// deliberate disconnection
server.disconnect();
// main interval to 5 seconds
MAIN_INTERVAL <- 5;
// tell my program that now im disconnected
DISCONNECTED <- true;`
The main “loop” or sensor post:
`// send sensor values
function send_sensors_to_agent()
{
if(!DISCONNECTED) server.log("sending values...");
if(DISCONNECTED) {
server.connect(disconnection_handler, 30);
} else {
send values to db . . .
}
imp.wakeup(MAIN_INTERVAL, send_sensors_to_agent);
}`
And my start up function which will start send_sensors_to_agent() and load saved perferences table is called in the buttom of the code (any issue with that?).
So upon connection, I’ll put my interval to 60 seconds of sensor posting, and when disonnected 5 seconds for checking the connection (i want to be online, and have power - so i want to get back online fast!)
The problem right now is, that cutting the wifi and putting it back again works perfectly fine, as it’s handled by the server.onunexpecteddisconnect method. But when cutting the wifi AND the power, it seems like it’s following the SUSPEND_ON_ERROR flow, and not starting squirrel.