I'd suggest to place the code for "wifi.on('disconnected',..." into the "wifi.on('connected'," function. I didn't try this, but as the disconnect function gets registered after every connect it should work.
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.
I'd suggest to place the code for "wifi.on('disconnected',..." into the "wifi.on('connected'," function. I didn't try this, but as the disconnect function gets registered after every connect it should work.