From b76a63fd0485d6164175535b4c99f81c8d544fa7 Mon Sep 17 00:00:00 2001 From: Merlin Schumacher Date: Mon, 22 Oct 2018 17:17:11 +0200 Subject: [PATCH] Revert "Various small changes" --- Basecamp.cpp | 32 ++++++++++++++++---------------- Configuration.hpp | 45 +-------------------------------------------- WifiControl.cpp | 10 ++-------- WifiControl.hpp | 1 - 4 files changed, 19 insertions(+), 69 deletions(-) diff --git a/Basecamp.cpp b/Basecamp.cpp index e7b3ff2..27a42fa 100644 --- a/Basecamp.cpp +++ b/Basecamp.cpp @@ -28,7 +28,7 @@ Basecamp::Basecamp(SetupModeWifiEncryption setupModeWifiEncryption, Configuratio */ String Basecamp::_cleanHostname() { - String clean_hostname = configuration.get(ConfigurationKey::deviceName); // Get device name from configuration + String clean_hostname = configuration.get("DeviceName"); // Get device name from configuration // If hostname is not set, return default if (clean_hostname == "") { @@ -130,9 +130,9 @@ bool Basecamp::begin(String fixedWiFiApEncryptionPassword) // Initialize Wifi with the stored configuration data. wifi.begin( - configuration.get(ConfigurationKey::wifiEssid), // The (E)SSID or WiFi-Name - configuration.get(ConfigurationKey::wifiPassword), // The WiFi password - configuration.get(ConfigurationKey::wifiConfigured), // Has the WiFi been configured + configuration.get("WifiEssid"), // The (E)SSID or WiFi-Name + configuration.get("WifiPassword"), // The WiFi password + configuration.get("WifiConfigured"), // Has the WiFi been configured hostname, // The system hostname to use for DHCP (setupModeWifiEncryption_ == SetupModeWifiEncryption::none)?"":configuration.get(ConfigurationKey::accessPointSecret) ); @@ -142,16 +142,16 @@ bool Basecamp::begin(String fixedWiFiApEncryptionPassword) #endif #ifndef BASECAMP_NOMQTT // Check if MQTT has been disabled by the user - if (!configuration.get(ConfigurationKey::mqttActive).equalsIgnoreCase("false")) { + if (configuration.get("MQTTActive") != "false") { // Setting up variables for the MQTT client. This is necessary due to // the nature of the library. It won't work properly with Arduino Strings. - const auto &mqtthost = configuration.get(ConfigurationKey::mqttHost); - const auto &mqttuser = configuration.get(ConfigurationKey::mqttUser); - const auto &mqttpass = configuration.get(ConfigurationKey::mqttPass); + const auto &mqtthost = configuration.get("MQTTHost"); + const auto &mqttuser = configuration.get("MQTTUser"); + const auto &mqttpass = configuration.get("MQTTPass"); // INFO: that library just copies the pointer to the hostname. As long as nobody // modifies the config, this may work. mqtt.setClientId(hostname.c_str()); - auto mqttport = configuration.get(ConfigurationKey::mqttPort).toInt(); + auto mqttport = configuration.get("MQTTPort").toInt(); if (mqttport == 0) mqttport = 1883; // INFO: that library just copies the pointer to the hostname. As long as nobody // modifies the config, this may work. @@ -175,10 +175,10 @@ bool Basecamp::begin(String fixedWiFiApEncryptionPassword) #ifndef BASECAMP_NOOTA // Set up Over-the-Air-Updates (OTA) if it hasn't been disabled. - if (!configuration.get(ConfigurationKey::otaActive).equalsIgnoreCase("false")) { + if(configuration.get("OTAActive") != "false") { // Set OTA password - String otaPass = configuration.get(ConfigurationKey::otaPass); + String otaPass = configuration.get("OTAPass"); if (otaPass.length() != 0) { ArduinoOTA.setPassword(otaPass.c_str()); } @@ -231,7 +231,7 @@ bool Basecamp::begin(String fixedWiFiApEncryptionPassword) web.setInterfaceElementAttribute("heading", "class", "fat-border"); web.addInterfaceElement("logo", "img", "", "#heading"); web.setInterfaceElementAttribute("logo", "src", "/logo.svg"); - String DeviceName = configuration.get(ConfigurationKey::deviceName); + String DeviceName = configuration.get("DeviceName"); if (DeviceName == "") { DeviceName = "Unconfigured Basecamp Device"; } @@ -257,7 +257,7 @@ bool Basecamp::begin(String fixedWiFiApEncryptionPassword) web.setInterfaceElementAttribute("WifiConfigured", "value", "true"); // Add input fields for MQTT configurations if it hasn't been disabled - if (!configuration.get(ConfigurationKey::mqttActive).equalsIgnoreCase("false")) { + if (configuration.get("MQTTActive") != "false") { web.addInterfaceElement("MQTTHost", "input", "MQTT Host:","#configform" , "MQTTHost"); web.addInterfaceElement("MQTTPort", "input", "MQTT Port:","#configform" , "MQTTPort"); web.setInterfaceElementAttribute("MQTTPort", "type", "number"); @@ -283,7 +283,7 @@ bool Basecamp::begin(String fixedWiFiApEncryptionPassword) web.setInterfaceElementAttribute("footerlink", "target", "_blank"); #ifdef BASECAMP_USEDNS #ifdef DNSServer_h - if (!configuration.get(ConfigurationKey::wifiConfigured).equalsIgnoreCase("true")) { + if(configuration.get("WifiConfigured") != "True"){ dnsServer.start(53, "*", wifi.getSoftAPIP()); xTaskCreatePinnedToCore(&DnsHandling, "DNSTask", 4096, (void*) &dnsServer, 5, NULL,0); } @@ -391,7 +391,7 @@ void Basecamp::checkResetReason() if (bootCounter > 3){ DEBUG_PRINTLN("Configuration forcibly reset."); // Mark the WiFi configuration as invalid - configuration.set(ConfigurationKey::wifiConfigured, "False"); + configuration.set("WifiConfigured", "False"); // Save the configuration immediately configuration.save(); // Reset the boot counter @@ -403,7 +403,7 @@ void Basecamp::checkResetReason() ESP.restart(); // If the WiFi is unconfigured and the device is rebooted twice format the internal flash storage - } else if (bootCounter > 2 && configuration.get(ConfigurationKey::wifiConfigured).equalsIgnoreCase("false")) { + } else if (bootCounter > 2 && configuration.get("WifiConfigured") == "False") { Serial.println("Factory reset was forced."); // Format the flash storage SPIFFS.format(); diff --git a/Configuration.hpp b/Configuration.hpp index aa7ab1d..d0f2349 100644 --- a/Configuration.hpp +++ b/Configuration.hpp @@ -17,18 +17,7 @@ // TODO: Extend with all known keys enum class ConfigurationKey { - deviceName, accessPointSecret, - wifiConfigured, - wifiEssid, - wifiPassword, - mqttActive, - mqttHost, - mqttPort, - mqttUser, - mqttPass, - otaActive, - otaPass, }; // TODO: Extend with all known keys @@ -38,41 +27,9 @@ static const String getKeyName(ConfigurationKey key) // (if the warnings are turned on exactly...) switch (key) { - case ConfigurationKey::deviceName: - return "DeviceName"; - case ConfigurationKey::accessPointSecret: return "APSecret"; - - case ConfigurationKey::wifiConfigured: - return "WifiConfigured"; - - case ConfigurationKey::wifiEssid: - return "WifiEssid"; - - case ConfigurationKey::wifiPassword: - return "WifiPassword"; - - case ConfigurationKey::mqttActive: - return "MQTTActive"; - - case ConfigurationKey::mqttHost: - return "MQTTHost"; - - case ConfigurationKey::mqttPort: - return "MQTTPort"; - - case ConfigurationKey::mqttUser: - return "MQTTUser"; - - case ConfigurationKey::mqttPass: - return "MQTTPass"; - - case ConfigurationKey::otaActive: - return "OTAActive"; - - case ConfigurationKey::otaPass: - return "OTAPass"; + break; } return ""; } diff --git a/WifiControl.cpp b/WifiControl.cpp index 92c7691..27ed11a 100644 --- a/WifiControl.cpp +++ b/WifiControl.cpp @@ -19,12 +19,10 @@ void WifiControl::begin(String essid, String password, String configured, String _wifiConfigured = std::move(configured); _wifiEssid = std::move(essid); _wifiPassword = std::move(password); - if (_wifiAPName.length() == 0) { - _wifiAPName = "ESP32_" + getHardwareMacAddress(); - } + _wifiAPName = "ESP32_" + getHardwareMacAddress(); WiFi.onEvent(WiFiEvent); - if (_wifiConfigured.equalsIgnoreCase("true")) { + if (_wifiConfigured == "True") { operationMode_ = Mode::client; DEBUG_PRINTLN("Wifi is configured"); DEBUG_PRINT("Connecting to "); @@ -67,10 +65,6 @@ IPAddress WifiControl::getSoftAPIP() { return WiFi.softAPIP(); } -void WifiControl::setAPName(const String &name) { - _wifiAPName = name; -} - String WifiControl::getAPName() { return _wifiAPName; } diff --git a/WifiControl.hpp b/WifiControl.hpp index 3b54cd7..1533a84 100644 --- a/WifiControl.hpp +++ b/WifiControl.hpp @@ -32,7 +32,6 @@ class WifiControl { String hostname = "BasecampDevice", String apSecret=""); IPAddress getIP(); IPAddress getSoftAPIP(); - void setAPName(const String &name); String getAPName(); int status(); static void WiFiEvent(WiFiEvent_t event);