Restore Wifi connection after router reboot

Posted on
  • Hello,

    Does anybody have a solid method to automatically restore the Wifi connection on an ESP32 after losing it, for instance after a router reboot?

    Thanks a lot!

    Regards,
    Ronald

  • This is what I use

    function wifiConnect() {
      wifi = require('Wifi');
      wifi.connect(wifi_options.ssid, { password: wifi_options.password },
        (e)=> {
          if (e) {
            print("WIFI: " + e);
          }
      });
      wifi.on('connected', ()=> {
        print('WIFI:', wifi.getIP());
      });
      wifi.on('disconnected', ()=> {
        print("WIFI: Reconectando...");
        wifi.connect(wifi_options.ssid, {password: wifi_options.password});
      });
    }
    
  • Perfect, thanks a lot! I did not expect the disconnected event to trigger when connect() fails.

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

Restore Wifi connection after router reboot

Posted by Avatar for Rovale @Rovale

Actions