I am using an ESP 12e on a MQTT system. When it first starts up I have wifiManager open an access point so the user can put in the wifi, password, MQTT name and Key. This all works fine.
However every once in a while something happens (like an electrical interrupt) and the ESP 12e starts up and looks for the wifi to connect to but because of the power outage the wifi isn't up and running yet so it starts the access point. If this occurs while I am away the ESP 12e just sits there in access mode waiting for someone to enter the data until I return home and restart the ESP 12e manually while the wifi is broadcasting.
I am trying to program the ESP 12e to restart after a certain amount of time (6 minutes) when the wifi has had time to start broadcasting again.
I am using Arduino IDE.
void setup() {
Serial.begin(57600);
//NEW AUTOCONNECT
WiFiManager wifiManager;
// I added three extra parameters.
WiFiManagerParameter customAPIKey("authorizationKey", "Authorization Code",authorizationKey, 32);
WiFiManagerParameter customAPIKey2("apiKey", "Time Zone #", apiKey, 32);
WiFiManagerParameter customAPIKey3("userNameKey", "User Name",userNameKey, 32);
wifiManager.addParameter(&customAPIKey);
wifiManager.addParameter(&customAPIKey2);
wifiManager.addParameter(&customAPIKey3);
//this is where I put your code
wifiManager.setTimeout(120); // 2 minutes
do {
WiFi.begin();
wifiManager.autoConnect("LEVEL1");
} while (WiFi.status() != WL_CONNECTED);
//I get the data captured by wifiManager AP
strcpy(authorizationKey, customAPIKey.getValue());
strcpy(apiKey, customAPIKey2.getValue());
strcpy(userNameKey, customAPIKey3.getValue());
EEPROM.begin(512); //Initialize EEPROM
String rrr = apiKey;
//If there is no data input I wait for data to be input to AP
if (rrr.length() == 0){
Serial.print ("empty");
//Store data to EEPROM
}
//If there is input data I write it to EEPROM
else {
Serial.print ("Not Empty");
String uuu = authorizationKey;
String www = apiKey;
String yyy = userNameKey;
String fff = String(www)+String(",");
String vvv = String(yyy)+String(",");
for(int i=0;i<uuu.length();i++) //loop upto string lenght www.length() returns length of string
{
EEPROM.write(0x06+i,uuu[i]); //Write one by one with starting address of 0x0F
}
for(int i=0;i<fff.length();i++) //loop upto string lenght www.length() returns length of string
{
EEPROM.write(0x50+i,fff[i]); //Write one by one with starting address of 0x0F
}
for(int i=0;i<vvv.length();i++) //loop upto string lenght www.length() returns length of string
{
EEPROM.write(0x90+i,vvv[i]); //Write one by one with starting address of 0x0F
}
EEPROM.commit();
}
delay (2000);
//If the ESP 12e connects using the wifiManager stored name and password I retrieve the data from EEPROM and used it to connect to Adafruit.
if (WiFi.status() == WL_CONNECTED) { Serial.println("Connected1");
delay(1000);
I start up the ESP 12e and the AP pops up. I fill in the wifi.name and password and the other added parameters and save them. It then connects to the wifi and adafruit.
If I unplug the ESP and the router and then launch the ESP 12e it tries to use the last saved values but since there is no wifi it starts the AP. If I wait two minutes the serial monitors shows that the ESP 12e tries to reconnect with the saved values but can't. Then I restart the router and the wifi come back. The next time the ESP 12e times out it tries to reconnect using saved values but it doesn't and it starts the AP again. Over and over again.
Somewhere I have done something wrong. Could you suggest something.