Improve reconnect
This commit is contained in:
@@ -5,7 +5,9 @@
|
||||
WIFIMANAGER Network::WifiManager;
|
||||
AsyncWebServer Network::webServer(80);
|
||||
|
||||
Network::Network(std::string_view hostname, std::string_view apSsid) : hostname(hostname), apSsid(apSsid) {
|
||||
Network::Network(std::string_view hostname, std::string_view apSsid) {
|
||||
this->hostname = std::string(hostname);
|
||||
this->apSsid = std::string(apSsid);
|
||||
setHostname(hostname);
|
||||
WifiManager.startBackgroundTask(apSsid.data(), "");
|
||||
WifiManager.fallbackToSoftAp(true);
|
||||
@@ -23,6 +25,11 @@ Network::~Network() {
|
||||
WifiManager.detachWebServer();
|
||||
}
|
||||
|
||||
void Network::reconnect() {
|
||||
WifiManager.stopWifi(true);
|
||||
WifiManager.startBackgroundTask(apSsid.data(), "");
|
||||
}
|
||||
|
||||
bool Network::isConnected() const {
|
||||
return WiFi.status() == WL_CONNECTED;
|
||||
}
|
||||
@@ -32,13 +39,14 @@ std::string Network::getHostname() const {
|
||||
}
|
||||
|
||||
bool Network::setHostname(const std::string_view &hostname) {
|
||||
return WiFi.setHostname(hostname.data());
|
||||
this->hostname = std::string(hostname);
|
||||
return WiFi.setHostname(this->hostname.c_str());
|
||||
}
|
||||
|
||||
void Network::registerMDNS() {
|
||||
if (!MDNS.begin(hostname.data())) {
|
||||
if (!MDNS.begin(this->hostname.c_str())) {
|
||||
Serial.println("Error setting up MDNS responder!");
|
||||
} else {
|
||||
Serial.printf("mDNS responder started with hostname: %s\n", hostname.data());
|
||||
Serial.printf("mDNS responder started with hostname: %s\n", this->hostname.c_str());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user