var wifi;
var wifiTry = 1;
function connectWifi(){
console.log("Connecting to WiFi");
wifi.connect("access","password", function(err) {
if (err) {
throw err;
}
console.log("Connected!");
wifi.getIP(function(e, ip) {
LED2.set();
console.log(ip);
});
});
}
//checks the ESP8266 connection status
function espStatus(callback){
wifi.at.cmd('AT+CIPSTATUS\r\n',1000,function(d){
console.log('ESP8266 '+d);
var status = d.slice(-1);//get the last character
if(status == 2){//connection is good
console.log('good connection');
wifiTry=0;
}else if(wifiTry>1){
clearInterval();//clearInterval is causing issues here
wifiTry=0;
console.log('end');
}else{//connection is bad and we need to reconnect
wifiTry++;
console.log('bad connection');
//need timeout to give esp8266 time to think.
setTimeout(connectWifi,500);
}
});
}
function onInit() {
clearInterval();
E.enableWatchdog(10, true); //should restart the pico if it freezes
// initialise the ESP8266, after a delay
setTimeout(function() {
digitalWrite(B9,1); // enable on Pico Shim V2
Serial2.setup(115200, { rx: A3, tx : A2 });
wifi = require("ESP8266WiFi_0v25").connect(Serial2, function(err){
if(err){
throw err;
}
connectWifi();
setInterval(espStatus, 30000);
});
}, 2000);
}
And this is the error:
Uncaught Error: Unknown Timeout
at line 1 col 52
...))?(d=p,b=f):clearTimeout(e);void 0===d&&0<g.length&&(a=g.sh...
^
in function "d" called from line 1 col 324
...c&&(e[c](k),n=!0);n||d&&d(k)}a=a.substr(f+1);"\n"==a[0]&&(a=...
^
in function called from system
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
Here is an example that causes errors...
And this is the error: