WiFiManager: Connect to known SSID after a power failure? dont start a new access point.

Basic Infos

Hardware

WiFimanager Branch/Release: Master

Esp8266/Esp32:

Hardware: D1 mini

Description

Im trying to reconnect to my known SSID that was successful but i cannot reconnect to it after a power outage. All the device does is boot up another AP which i dont want. I have tried multiple ways to keep restarting the device, wifi begin etc etc but i always starts a new AP on SSID not found boot up.

What i want to achieve: After a power outage for the ESP device to keep retrying the known SSID from the config file. I will handle a reset for AP manually if i wish to but all i want is on boot for the device to keep trying to connect to the known SSID as the routers take a while to boot.

Settings in IDE

Module: Wemos D1

Additional libraries:

Sketch

#BEGIN
#include <Arduino.h>

void setup() {
  Serial.begin(9600);

  bool spiffsSetup = loadConfigFile();
  if (!spiffsSetup)
  {
    Serial.println(F("Forcing config mode as there is no saved config"));
    forceConfig = true;
  }

  setupWifiManager();
}

void loop() {
   //Continue to connect to MQTT and reconnect if dropped. Connect to known SSID on boot and dont start a new AP.
  //Listen for button press to start AP if i wish to.
}

void setupWifiManager()
{
  WiFiManagerParameter custom_mqtt_server("server", "mqtt server", mqtt_server, 20);
  WiFiManagerParameter custom_mqtt_port("port", "mqtt port", mqtt_port, 10);
  WiFiManagerParameter custom_mqtt_user("user", "mqtt user", mqtt_user, 50);
  WiFiManagerParameter custom_mqtt_pass("pass", "mqtt pass", mqtt_pass, 50);

  // WiFiManager
  // Local intialization. Once its business is done, there is no need to keep it around
  WiFiManager wifiManager;

  //set config save notify callback
  wifiManager.setSaveConfigCallback(saveConfigCallback);

  //add all your parameters here
  wifiManager.addParameter(&custom_mqtt_server);
  wifiManager.addParameter(&custom_mqtt_port);
  wifiManager.addParameter(&custom_mqtt_user);
  wifiManager.addParameter(&custom_mqtt_pass);

  //sets timeout until configuration portal gets turned off
  //useful to make it all retry or go to sleep
  //in seconds
  wifiManager.setConfigPortalTimeout(180);
  if(forceConfig) {
    wifiManager.autoConnect("AP");  
  }
}
#END

Debug Messages

messages here

About this issue

Most upvoted comments

@SboleWork Hi. Got it sorted.

If it fails to connect to the known network - i.e. the router isn't up yet, it reverts to AP mode and allows me to connect to it and search for networks. - this was my problem. the router didnt boot fast enough and the tries were only a handful before it reverted to AP mode which i didnt want.

Now it tries for a long time and eventually connects. I have a button which i use to revert back to AP mode.

I used the manager in my geyserwise project.

https://github.com/jackkitley/geyserwise_max_iot