you need to watch for wifi.on("connected") events - and in this function do your MQTT setup.
So if the connection is dropped, or the board restarts, it will then run this code.
There is some discussion on gitter about this - you might ask them to post their code so you can see how they have set it up...
https://gitter.im/espruino/Espruino?at=58ee1f738e4b63533dbfad9e
Something like:
function Start() { console.log("starting servers"); var http = require('http').createServer(onPageRequest); http.listen(80); } var wifi=require("Wifi"); wifi.on('connected', Start );
@Wilberforce started
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.
you need to watch for wifi.on("connected") events - and in this function do your MQTT setup.
So if the connection is dropped, or the board restarts, it will then run this code.
There is some discussion on gitter about this - you might ask them to post their code so you can see how they have set it up...
https://gitter.im/espruino/Espruino?at=58ee1f738e4b63533dbfad9e
Something like: