mirror of
https://github.com/alexhopeoconnor/WiFiManager.git
synced 2026-10-15 23:51:20 +10:00
Adding Static IP Support
This commit is contained in:
@@ -201,6 +201,13 @@ This will set your captive portal to a specific IP should you need/want such a f
|
||||
//set custom ip for portal
|
||||
wifiManager.setAPConfig(IPAddress(10,0,1,1), IPAddress(10,0,1,1), IPAddress(255,255,255,0));
|
||||
```
|
||||
|
||||
### Custom Static IP Configuration
|
||||
This will make use the specified IP configuration instead of using DHCP.
|
||||
```
|
||||
wifiManager.setStaticIPConfig(IPAddress(192,168,0,99), IPAddress(192,168,0,1), IPAddress(255,255,255,0));
|
||||
```
|
||||
|
||||
#### Filter Networks
|
||||
If you would like to filter low signal quality networks you can tell WiFiManager to not show networks below an arbitrary quality %;
|
||||
```
|
||||
|
||||
@@ -113,6 +113,12 @@ boolean WiFiManager::autoConnect(char const *apName, char const *apPassword) {
|
||||
|
||||
// attempt to connect; should it fail, fall back to AP
|
||||
WiFi.mode(WIFI_STA);
|
||||
|
||||
// check if we've got static_ip settings, if we do, use those.
|
||||
if (_static_ip){
|
||||
WiFi.config(_static_ip, _static_gw, _static_sn);
|
||||
}
|
||||
|
||||
if (connectWifi(ssid, pass) == WL_CONNECTED) {
|
||||
DEBUG_WM(F("IP Address:"));
|
||||
DEBUG_WM(WiFi.localIP());
|
||||
@@ -266,6 +272,12 @@ void WiFiManager::setAPConfig(IPAddress ip, IPAddress gw, IPAddress sn) {
|
||||
_sn = sn;
|
||||
}
|
||||
|
||||
void WiFiManager::setStaticIPConfig(IPAddress static_ip, IPAddress static_gw, IPAddress static_sn) {
|
||||
_static_ip = static_ip;
|
||||
_static_gw = static_gw;
|
||||
_static_sn = static_sn;
|
||||
}
|
||||
|
||||
void WiFiManager::setMinimumSignalQuality(int quality) {
|
||||
_minimumQuality = quality;
|
||||
}
|
||||
|
||||
+5
-2
@@ -82,14 +82,14 @@ class WiFiManager
|
||||
void setDebugOutput(boolean debug);
|
||||
//defaults to not showing anything under 8% signal quality if called
|
||||
void setMinimumSignalQuality(int quality = 8);
|
||||
|
||||
//sets a custom ip /gateway /subnet configuration
|
||||
void setAPConfig(IPAddress ip, IPAddress gw, IPAddress sn);
|
||||
//sets config for a static IP
|
||||
void setStaticIPConfig(IPAddress static_ip, IPAddress static_gw, IPAddress static_sn);
|
||||
//called when AP mode and config portal is started
|
||||
void setAPCallback( void (*func)(WiFiManager*) );
|
||||
//called when settings have been changed and connection was successful
|
||||
void setSaveConfigCallback( void (*func)(void) );
|
||||
|
||||
//adds a custom parameter
|
||||
void addParameter(WiFiManagerParameter *p);
|
||||
|
||||
@@ -114,6 +114,9 @@ class WiFiManager
|
||||
IPAddress _ip;
|
||||
IPAddress _gw;
|
||||
IPAddress _sn;
|
||||
IPAddress _static_ip;
|
||||
IPAddress _static_gw;
|
||||
IPAddress _static_sn;
|
||||
int _paramsCount = 0;
|
||||
int _minimumQuality = -1;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user