简体   繁体   中英

espruino: wifi on connect event not fired

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:**"
 }

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM