-
• #2
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 );
Using the ESP8266 I've managed a connection - no problem - and an MQTT (https://www.espruino.com/MQTT) connect - with subscribe. All works swimmingly well.
But, if you disconnect and reconnect the router, you've lost your MQTT connection and subscribes - although the WIFI does seem to reconnect automatically.
Has anyone already written something to check for broken MQTT connect - and reconnect automatically? (without which of course it isn't a lot of use :-) )