some big change using state machine
This commit is contained in:
@@ -5,14 +5,14 @@
|
||||
WIFIMANAGER Network::WifiManager;
|
||||
AsyncWebServer Network::webServer(80);
|
||||
|
||||
Network::Network(std::string hostname, std::string apSsid) : hostname(hostname), apSsid(apSsid) {
|
||||
Network::Network(std::string_view hostname, std::string_view apSsid) : hostname(hostname), apSsid(apSsid) {
|
||||
setHostname(hostname);
|
||||
WifiManager.startBackgroundTask(apSsid.c_str(), "");
|
||||
WifiManager.startBackgroundTask(apSsid.data(), "");
|
||||
WifiManager.fallbackToSoftAp(true);
|
||||
WifiManager.attachWebServer(&webServer);
|
||||
WifiManager.attachUI();
|
||||
webServer.on("/", HTTP_GET, [this](AsyncWebServerRequest *request) {
|
||||
request->send(200, "text/html", this->defaultHomepage.c_str());
|
||||
request->send(200, "text/html", this->defaultHomepage.data());
|
||||
});
|
||||
webServer.begin();
|
||||
}
|
||||
@@ -25,14 +25,14 @@ std::string Network::getHostname() const {
|
||||
return WiFi.getHostname();
|
||||
}
|
||||
|
||||
bool Network::setHostname(const std::string &hostname) {
|
||||
return WiFi.setHostname(hostname.c_str());
|
||||
bool Network::setHostname(const std::string_view &hostname) {
|
||||
return WiFi.setHostname(hostname.data());
|
||||
}
|
||||
|
||||
void Network::registerMDNS() {
|
||||
if (!MDNS.begin(hostname.c_str())) {
|
||||
if (!MDNS.begin(hostname.data())) {
|
||||
Serial.println("Error setting up MDNS responder!");
|
||||
} else {
|
||||
Serial.printf("mDNS responder started with hostname: %s\n", hostname.c_str());
|
||||
Serial.printf("mDNS responder started with hostname: %s\n", hostname.data());
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,13 @@
|
||||
#include <Arduino.h>
|
||||
#include <string_view>
|
||||
#include "wifimanager.h"
|
||||
|
||||
class Network {
|
||||
public:
|
||||
Network(std::string hostname, std::string apSsid = "Smart RGB");
|
||||
Network(std::string_view hostname, std::string_view apSsid = "Smart RGB");
|
||||
bool isConnected() const;
|
||||
std::string getHostname() const;
|
||||
bool setHostname(const std::string &hostname);
|
||||
bool setHostname(const std::string_view &hostname);
|
||||
void registerMDNS();
|
||||
private:
|
||||
static WIFIMANAGER WifiManager;
|
||||
@@ -25,6 +26,6 @@ private:
|
||||
<p><small>ESP32 WiFi Manager (c) 2022-2025 by Martin Verges</small></p>
|
||||
</body></html>
|
||||
)html";
|
||||
std::string hostname;
|
||||
std::string apSsid; // SSID for the fallback AP
|
||||
std::string_view hostname;
|
||||
std::string_view apSsid; // SSID for the fallback AP
|
||||
};
|
||||
Reference in New Issue
Block a user