I want to be able to break the loop and start a softAP in event of an unsuccessful connect to WAN. I can break the while loop, and start a softAP. However, while the softAP starts and I can see its SSID on my laptop, it is very slow to connect and does not support the webserver which is running on the ESP. (In other words, the laptop connects, but Chrome says I am not connected to the internet and shows file not found errors.)
As long as wifiMulti connects to a viable network, everything runs smoothly using the ESP in _AP_STA mode. Or, if I comment out setupWifi() and use only apWifi(), everything runs smoothly using the ESP in _AP mode. It is only when wifiMulti fails to connect that I get hung up.
What do I need to do to disable wifiMulti when I break the loop? It seems to be negatively interfering with the softAP ability to establish a connection for the webserver. Thank you.
Here are some of the code snippets:
In my globals:
#include <ESP8266WiFi.h>
#include <ESP8266WiFiMulti.h>
#include <ESP8266WebServer.h>
ESP8266WiFiMulti wifiMulti;
ESP8266WebServer server(80);
//set up all of the necessary variables
This function is called from setup. It sets up wifiMulti.
void setupWifi() {
// WiFi.mode(WIFI_AP_STA);
aptime = millis();
wifiMulti.addAP("SSID1","PW1");
wifiMulti.addAP("SSID2", "PW2");
wifiMulti.addAP("SSID3", "PW3");
wifiMulti.addAP("SSID4", PW4");
Serial.println("Connecting Wifi...");
while (wifiMulti.run() != WL_CONNECTED) {
if (millis()-aptime >= apdelay) {
Serial.println("Network Failed");
break;
}
Serial.print(".");
delay(500);
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("Connected to SSID: ");
Serial.println(WiFi.SSID());
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
}
This function is called from setup to set up the softAP. After wifiMulti is called.
void apWifi () {
//Setup softAP to run befor WiFiMulti
Serial.print("Configuring access point...");
WiFi.softAP("Box", "a");
IPAddress myIP = WiFi.softAPIP();
Serial.print("AP IP address: ");
Serial.println(myIP);
}
My void Setup has these bits, among many others to start up the wifi and server.
Void Setup(){
//… lots of variables, etc.
setupWifi();
apWifi():
server.on("/setup", handleConfigureDevice);
server.on("/update",handleUpdate);
server.onNotFound(handleNotFound);
server.begin();
Serial.println("HTTP Server Started");
void loop() {
server.handleClient();
}