Skip to content
This repository was archived by the owner on Feb 8, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions docs/wifi-manager.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ void setNewWifi(String newSSID, String newPass, String newIp, String newSub, Str
```
Tries to connect to the WiFi network with SSID `newSSID` and password `newPass`. If this fails a reconnect to the known network will be attempted. If this also fails or if no previous network was known, a captive portal will be started. Alternatively the function can also be called with inputs for a static IP address if DHCP is not available.

#### forgetWiFiFunctionCallback() and newWiFiFunctionCallback

```c++
void forgetWiFiFunctionCallback( std::function<void()> func );
void newWiFiFunctionCallback( std::function<void()> func );
```
This functions is called at the end of forget WiFi or after new WiFi is configured. This would be helpful to execute your code after a WiFi configuration or after you delete a WiFi configuration from Devices

## Web interface

The page in the web interface that is connected to the WiFi settings is shown below. For now this is a simple page that:
Expand Down
22 changes: 20 additions & 2 deletions src/WiFiManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ void WifiManager::forget()
//make EEPROM empty
storeToEEPROM();

if ( _forgetwificallback != NULL) {
_forgetwificallback();
}

Serial.println(PSTR("Requested to forget WiFi. Started Captive portal."));
}

Expand Down Expand Up @@ -169,6 +173,10 @@ void WifiManager::connectNewWifi(String newSSID, String newPass)
//store IP address in EEProm
storeToEEPROM();

if ( _newwificallback != NULL) {
_newwificallback();
}

}
}
}
Expand All @@ -193,6 +201,7 @@ void WifiManager::startCaptivePortal(char const *apName)
Serial.println(PSTR("Opened a captive portal"));
Serial.println(PSTR("192.168.4.1"));
inCaptivePortal = true;

}

//function to stop the captive portal
Expand All @@ -201,7 +210,15 @@ void WifiManager::stopCaptivePortal()
WiFi.mode(WIFI_STA);
delete dnsServer;

inCaptivePortal = false;
inCaptivePortal = false;
}

void WifiManager::forgetWiFiFunctionCallback( std::function<void()> func ) {
_forgetwificallback = func;
}

void WifiManager::newWiFiFunctionCallback( std::function<void()> func ) {
_newwificallback = func;
}

//return captive portal state
Expand Down Expand Up @@ -241,4 +258,5 @@ void WifiManager::storeToEEPROM()
configManager.internal.sub = sub.v4();
configManager.internal.dns = dns.v4();
configManager.save();
}
}

4 changes: 4 additions & 0 deletions src/WiFiManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ class WifiManager
void connectNewWifi(String newSSID, String newPass);
void storeToEEPROM();
int8_t waitForConnectResult(unsigned long timeoutLength);
std::function<void()> _forgetwificallback;
std::function<void()> _newwificallback;

public :
void begin(char const *apName, unsigned long newTimeout = 60000);
Expand All @@ -35,6 +37,8 @@ public :
String SSID();
void setNewWifi(String newSSID, String newPass);
void setNewWifi(String newSSID, String newPass, String newIp, String newSub, String newGw, String newDns);
void forgetWiFiFunctionCallback( std::function<void()> func );
void newWiFiFunctionCallback( std::function<void()> func );
};

extern WifiManager WiFiManager;
Expand Down