espruino: wifi on connect event not fired

285 Views Asked by At

I need to be notified when the ESP8266 get connected to the WiFi network. To do so I'm listening to the connected event in the WiFi module. The callback function is never called.

The code:

var wifi = require("Wifi");

wifi.on('connected', function(details) { 
  console.log('connected to wifi', details);
});

wifi.connect("*****", {password:"****"}, function(err){
    console.log("connected? err=", err, "info=", wifi.getIP());
});

The output:

>
=undefined
connected? err= null info= {
  "ip": "192.168.1.105",
  "netmask": "255.255.255.0",
  "gw": "192.168.1.1",
  "mac": "5c:**:7f:**:7a:**"
 }
1

There are 1 best solutions below

0
On BEST ANSWER

The event is not fired because the ESP8266 was already connected to the WiFi network. When you setup your connection you can save the settings in order to get Espruino reconnect to the WiFi automatically at boot time.