Espruino Wifi - How to reconnect?

Posted on
  • Hello,
    since the EspruinoWiFi module does not support all the functions of the WiFi module ( like on('disconnect', ...) or getDetails() ) yet, I was wondering how I can reconnect to my network after a disconnect.

    Thanks for any suggestions and best regards

  • Hi,
    is this about ESP8266 modules like ESP-12F? Hope sample below will help to you:

    var wifi=require("Wifi");
    wifi.on('connected',function(details){ ... });
    wifi.on('disconnected',function(details)­{ ... });
    wifi.on('associated',function(details){ ... });
    wifi.on('sta_joined',function(details){ ... });
    wifi.on('sta_left',function(details){ ... });
    wifi.on('auth_change',function(details){­ ... });
    wifi.on('dhcp_timeout',function(){ ... });
    
  • Nope, this is for http://www.espruino.com/WiFi - the Espruino board with Wifi on it

    For now, you should be able to do:

    wifi.at.registerLine("WIFI DISCONNECT", function() {
      ...
    });  
    

    I haven't tested that but I believe it should work.

    However you should also be able to check wifi.getIP - if it fails then you'll know you're not connected.

  • Thanks for the fast answer @Gordon.
    Unfortunately both solutions do not seem to work for me.

    I get the following errors:

    >Uncaught Error: Field or method "registerLine" does not already exist, and can't create it on undefined
     at line 1 col 13293
    ...ted',function(a){}),wifi.at.registerL­ine('WIFI DISCONNECT',f...
    

    and

    Uncaught Error: Function "a" not found!
     at line 1 col 165
    ...ce(15,-1);else if("OK"==d){a(null,b);return}return h}
                                  ^
    in function "b" called from line 1 col 25
    d=void 0;var f;b&&(f=b(a))?(d=p,b=f):clearTimeout(e);­void 0=...
                            ^
    in function "d" called from line 1 col 324
    ...c&&(e[c](k),n=!0);n||d&&d(k)}a=a.subs­tr(f+1);"\n"==a[0]&&(a=...
                                  ^
    in function called from system
    Uncaught Error: Function "a" not found!
     at line 1 col 15
    if(void 0===d)a("Timeout");else{if("+CIFSR:STAIP­"==d.substr(...
                  ^
    in function "b" called from line 1 col 15
    d=void 0;b&&b()
                  ^
    in function called from system
    

    respectively

    Right now i use version 1v87, might that cause wifi.getIP() not to work?

  • So you've previously done wifi = require("EspruinoWiFi");, or is the wifi variable named something else?

    I tested both and they seem to work on 1v91 - but to be honest there shouldn't be a great deal of difference between that an 1v87 as they'll both be using the same module.

    You need to use wifi.getIP like this:

    wifi.getIP(function(err,d) {
      if (d.ip===undefined || d.ip=="0.0.0.0") print("Not connected");
      else print("Connected");
    });
    
  • Before I did not use a callback function, since the reference says it is optional.

    With the callback you provided it worked without any issue.

    Thanks again @Gordon !
    Cheers

  • No problem - I guess you were looking at the reference for the Wifi object which is the ESP8266 build. It's a bit confusing :)

    There is a reference just for the WiFi board on http://www.espruino.com/WiFi#using-wifi that might be a bit more help

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

Espruino Wifi - How to reconnect?

Posted by Avatar for user69937 @user69937

Actions