28 #include <ESP8266WiFi.h> 29 #include <ESP8266WebServer.h> 32 #include <WebServer.h> 34 #include <DNSServer.h> 39 #include "user_interface.h" 41 #define ESP_getChipId() (ESP.getChipId()) 44 #define ESP_getChipId() ((uint32_t)ESP.getEfuseMac()) 85 boolean autoConnect(
const char* ssidName,
const char* ssidPassword = NULL, WiFiMode_t acWiFiMode = WIFI_STA);
109 boolean isIp(String str);
116 template <
typename Generic>
127 int _retryAttempts = 3;
128 int _connectionTimeoutSecs = 10;
129 int _apTimeoutMins = 3;
131 const byte DNS_PORT = 53;
133 long _lastAPPage = 0;
134 boolean _removeDuplicateAPs =
true;
135 int _minimumQuality = 8;
136 int _paramsCount = 0;
137 boolean _readyToConnect =
false;
139 String _password =
"";
143 std::unique_ptr<DNSServer> dnsServer;
145 std::unique_ptr<ESP8266WebServer> server;
147 std::unique_ptr<WebServer> server;
151 char _apPassword[64] ;
153 IPAddress _ap_static_ip;
154 IPAddress _ap_static_gw;
155 IPAddress _ap_static_sn;
156 IPAddress _sta_static_ip;
157 IPAddress _sta_static_gw;
158 IPAddress _sta_static_sn;
161 void (*_savecallback)(void) = NULL;
166 void handleParamRoot();
168 void handleWifi(
boolean scan);
169 void handleWifiSave();
173 void handleNotFound();
176 auto optionalIPFromString(T *obj,
const char *s) -> decltype( obj->fromString(s) ) {
177 return obj->fromString(s);
179 auto optionalIPFromString(...) ->
bool {
180 DEBUG_WC(
"NO fromString METHOD ON IPAddress, you need ESP8266 core 2.1.0 or newer for Custom IP configuration to work.");
void setDebug(boolean isDebug)
Used to turn on or off messages to the serial port/monitor.
Definition: WiFiConnect.cpp:1283
String toStringIp(IPAddress ip)
Function to return a IPAddress as a string representation.
Definition: WiFiConnect.cpp:1268
Stalls execution with an infinate loop.
Definition: WiFiConnect.h:52
virtual void displayON()
Virtual method overriden in WiFiConnectOLED.
Definition: WiFiConnect.cpp:119
Restarts the chip, allowing it to try to setup again. Handy for sensors when wifi is lost...
Definition: WiFiConnect.h:53
void addParameter(WiFiConnectParam *p)
Adds a custom parameter to be displayed in the accesspoint and parameters portals. Custom parameters can be used to save information that you do not want to hard code i.e. IP address, Port number that can be saved to the file system.
Definition: WiFiConnect.cpp:178
void setAPName(const char *apName)
Sets the name for the Access Point, setting a default based on the ESP chip id if needed...
Definition: WiFiConnect.cpp:142
virtual void displayManualReset()
Virtual method overriden in WiFiConnectOLED.
Definition: WiFiConnect.cpp:92
void setAPCallback(void(*func)(WiFiConnect *))
Sets the function to be called when we enter Access Point for configuration. Gets passed a the WiFiCo...
Definition: WiFiConnect.cpp:1203
virtual void displayConnected()
Virtual method overriden in WiFiConnectOLED.
Definition: WiFiConnect.cpp:65
virtual void displayConnecting(int attempt, int totalAttempts)
Virtual method overriden in WiFiConnectOLED.
Definition: WiFiConnect.cpp:56
Same as AP_RESTART.
Definition: WiFiConnect.h:54
virtual void displayTurnOFF(int ms=5000)
Virtual method overriden in WiFiConnectOLED.
Definition: WiFiConnect.cpp:101
virtual void displayAP()
Virtual method overriden in WiFiConnectOLED.
Definition: WiFiConnect.cpp:74
Class that stores a custom parameter.
Definition: WiFiConnectParam.h:44
virtual void displayLoop()
Virtual method overriden in WiFiConnectOLED.
Definition: WiFiConnect.cpp:110
void setAPModeTimeoutMins(int mins)
Sets the timeout for when the Access Point is idle.
Definition: WiFiConnect.cpp:129
boolean startParamsPortal()
Starts the custom Parameters Portal using default access point name and password. ...
Definition: WiFiConnect.cpp:191
boolean isIp(String str)
Function to check if a given string is an IP Address.
Definition: WiFiConnect.cpp:1250
void setSaveConfigCallback(void(*func)(void))
Sets the function to be called when we need to save the custom parameters/configuration.
Definition: WiFiConnect.cpp:1216
boolean startConfigurationPortal()
Starts the Access Portal for setting SSID and Password for connecting to a network and any custom use...
Definition: WiFiConnect.cpp:363
Class that helps to connect to WiFi networks, that also has captive portal web interface for configur...
Definition: WiFiConnect.h:64
void setConnectionTimeoutSecs(int timeout)
Sets how long to wait for the connection before failing.
Definition: WiFiConnect.cpp:634
virtual void displayParams()
Virtual method overriden in WiFiConnectOLED.
Definition: WiFiConnect.cpp:83
void resetSettings()
A helper to clear the settings for the last connected network. Remember to comment out or remove and ...
Definition: WiFiConnect.cpp:646
boolean _debug
Flag to determine wheter to output mesages or not.
Definition: WiFiConnect.h:115
WiFiConnect()
Create WiFiConnect class.
Definition: WiFiConnect.cpp:45
const char * getAPName()
Gets the Access Point name or the default based on the ESP chip id if not already set...
Definition: WiFiConnect.cpp:161
No action, continues to run code.
Definition: WiFiConnect.h:51
void setSTAStaticIPConfig(IPAddress ip, IPAddress gw, IPAddress sn)
Used to set a static ip/gateway and subnet mask for the local network.
Definition: WiFiConnect.cpp:1318
void setAPStaticIPConfig(IPAddress ip, IPAddress gw, IPAddress sn)
Used to set a static ip/gateway and subnet mask for the access point. IP and DNS Gateway are normally...
Definition: WiFiConnect.cpp:1300
int getRSSIasQuality(int RSSI)
Function to convert RSSI into a usable range 0-100 so we can use it to exclude poor networks...
Definition: WiFiConnect.cpp:1229
AP_Continue
Definition: WiFiConnect.h:50
const char * statusToString(int state)
A helper function to return the string version of a wifi network state.
Definition: WiFiConnect.cpp:671
void setRetryAttempts(int attempts)
Sets how many times we should try to connect to the WiFi network.
Definition: WiFiConnect.cpp:622
#define WiFiConnect_MAX_PARAMS
The maximum size of the param array and how many custom parameters we may have.
Definition: WiFiConnectParam.h:35
void DEBUG_WC(Generic text)
Outputs debug messages.
Definition: WiFiConnect.cpp:701
boolean autoConnect()
Tries to connect to the last connected WiFi network.
Definition: WiFiConnect.cpp:553
boolean captivePortal()
Redirect to captive portal if we get a request for another domain. Return true in that case so the pa...
Definition: WiFiConnect.cpp:1178