EspruinoWifi connected / disconnected event

Posted on
  • Hi There
    I just received a few espruino.wifi boards. Nice work!

    I try to detect the connected or disconnected event without success. I did not get any of this two events. No connected event on connect and no disconnect event when i switch off my wifi AP.

    Code:

    var wifi = require("EspruinoWiFi");
    var WIFI_NAME = "XYZ";
    var WIFI_OPTIONS = { password : "PW" };
    
    console.log('Starting...');
    
    wifi.on('connected', function(data) {
        console.log("> connected "+data);
    });
    wifi.on('disconnected', function(data) {
        console.log("> disconnected "+data);
    });
    
    wifi.connect(WIFI_NAME, WIFI_OPTIONS, function(err) {
        if (err) {
            console.log("Connection error: "+err);
    
            return;
        }
        wifi.getIP(function(f,ip) {
            console.log("Connected: ", ip);
        });
    });
    

    The console output is:

    _____                 _
    |   __|___ ___ ___ _ _|_|___ ___
    |   __|_ -| . |  _| | | |   | . |
    |_____|___|  _|_| |___|_|_|_|___|
              |_| http://espruino.com
     1v94 Copyright 2016 G.Williams
    >Starting...
    =undefined
    Connected:  {
      "ip": "192.168.68.175",
      "mac": "5c:cf:7f:c0:14:c8"
     }
    >
    
  • I'm afraid there aren't any events at the moment - where did you find out about them from? You could try this and see if it gives you what you need:

    wifi.at.registerLine("WIFI CONNECTED", function() { wifi.emit("connected"); }); 
    wifi.at.registerLine("WIFI DISCONNECT", function() { wifi.emit("disconnected"); }); 
    

    I'm afraid I don't have time to test at the moment, but if it doesn't break anything else I can add it to the module. You might need to use "WIFI GOT IP" instead of "WIFI CONNECTED" though - since I guess you care more about whether you have an IP address than if you're connected.

  • Many thanks Gorden.
    I was confused regarding the Wifi documentation here:

    https://www.espruino.com/Reference#l_Wif­i_connected

  • I know - it is a bit confusing. Ideally that'd be changed - at some point I'll try and bring everything in line a bit more.

    That Wifi library is ESP8266-only at the moment. I'm trying to get it and the EspruinoWiFi library in sync in the hope that at some point I will properly merge the two. Unfortunately we're not quite there yet.

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

EspruinoWifi connected / disconnected event

Posted by Avatar for Sacha @Sacha

Actions