diff --git a/README.md b/README.md index 72da0e0d8..adf4c9f28 100644 --- a/README.md +++ b/README.md @@ -179,7 +179,7 @@ The Web is based off Rick's awesome [esp8266-react](https://github.com/rjwats/es * `MqttStatus.cpp` added root["mqtt_fails"] * `SecuritySettingsService.cpp` added version to the JWT payload * `SecuritySettingsService.h` #include "../../src/version.h" - * `WiFiSettingsService.cpp` added WiFi.setOutputPower(20.0f) - removed + * `WiFiSettingsService.cpp` added WiFi.setOutputPower(20.0f), moved setHostname * `OTASettingsService.h` added #include "../../src/system.h" * `OTASettingsService.cpp` added call to emsesp::System::upload_status(true) * `features.ini`: -D FT_NTP=0 diff --git a/lib/framework/WiFiSettingsService.cpp b/lib/framework/WiFiSettingsService.cpp index 8f03a3e2f..2c9c9ad5e 100644 --- a/lib/framework/WiFiSettingsService.cpp +++ b/lib/framework/WiFiSettingsService.cpp @@ -1,27 +1,25 @@ #include -WiFiSettingsService::WiFiSettingsService(AsyncWebServer* server, FS* fs, SecurityManager* securityManager) : - _httpEndpoint(WiFiSettings::read, WiFiSettings::update, this, server, WIFI_SETTINGS_SERVICE_PATH, securityManager), - _fsPersistence(WiFiSettings::read, WiFiSettings::update, this, fs, WIFI_SETTINGS_FILE), - _lastConnectionAttempt(0) { - // We want the device to come up in opmode=0 (WIFI_OFF), when erasing the flash this is not the default. - // If needed, we save opmode=0 before disabling persistence so the device boots with WiFi disabled in the future. - if (WiFi.getMode() != WIFI_OFF) { - WiFi.mode(WIFI_OFF); - } +WiFiSettingsService::WiFiSettingsService(AsyncWebServer * server, FS * fs, SecurityManager * securityManager) + : _httpEndpoint(WiFiSettings::read, WiFiSettings::update, this, server, WIFI_SETTINGS_SERVICE_PATH, securityManager) + , _fsPersistence(WiFiSettings::read, WiFiSettings::update, this, fs, WIFI_SETTINGS_FILE) + , _lastConnectionAttempt(0) { + // We want the device to come up in opmode=0 (WIFI_OFF), when erasing the flash this is not the default. + // If needed, we save opmode=0 before disabling persistence so the device boots with WiFi disabled in the future. + if (WiFi.getMode() != WIFI_OFF) { + WiFi.mode(WIFI_OFF); + } - // Disable WiFi config persistance and auto reconnect - WiFi.persistent(false); - WiFi.setAutoReconnect(false); + // Disable WiFi config persistance and auto reconnect + WiFi.persistent(false); + WiFi.setAutoReconnect(false); #ifdef ESP32 - // Init the wifi driver on ESP32 - WiFi.mode(WIFI_MODE_MAX); - WiFi.mode(WIFI_MODE_NULL); - WiFi.onEvent( - std::bind(&WiFiSettingsService::onStationModeDisconnected, this, std::placeholders::_1, std::placeholders::_2), - WiFiEvent_t::SYSTEM_EVENT_STA_DISCONNECTED); - WiFi.onEvent(std::bind(&WiFiSettingsService::onStationModeStop, this, std::placeholders::_1, std::placeholders::_2), - WiFiEvent_t::SYSTEM_EVENT_STA_STOP); + // Init the wifi driver on ESP32 + WiFi.mode(WIFI_MODE_MAX); + WiFi.mode(WIFI_MODE_NULL); + WiFi.onEvent(std::bind(&WiFiSettingsService::onStationModeDisconnected, this, std::placeholders::_1, std::placeholders::_2), + WiFiEvent_t::SYSTEM_EVENT_STA_DISCONNECTED); + WiFi.onEvent(std::bind(&WiFiSettingsService::onStationModeStop, this, std::placeholders::_1, std::placeholders::_2), WiFiEvent_t::SYSTEM_EVENT_STA_STOP); #elif defined(ESP8266) // proddy added @@ -31,78 +29,81 @@ WiFiSettingsService::WiFiSettingsService(AsyncWebServer* server, FS* fs, Securit // high tx power causing weird behavior, slightly lowering from 20.5 to 20.0 may help stability // WiFi.setOutputPower(20.0f); // in dBm - _onStationModeDisconnectedHandler = WiFi.onStationModeDisconnected( - std::bind(&WiFiSettingsService::onStationModeDisconnected, this, std::placeholders::_1)); + _onStationModeDisconnectedHandler = WiFi.onStationModeDisconnected(std::bind(&WiFiSettingsService::onStationModeDisconnected, this, std::placeholders::_1)); #endif - addUpdateHandler([&](const String& originId) { reconfigureWiFiConnection(); }, false); + addUpdateHandler([&](const String & originId) { reconfigureWiFiConnection(); }, false); } void WiFiSettingsService::begin() { - _fsPersistence.readFromFS(); - reconfigureWiFiConnection(); + _fsPersistence.readFromFS(); + reconfigureWiFiConnection(); } void WiFiSettingsService::reconfigureWiFiConnection() { - // reset last connection attempt to force loop to reconnect immediately - _lastConnectionAttempt = 0; + // reset last connection attempt to force loop to reconnect immediately + _lastConnectionAttempt = 0; // disconnect and de-configure wifi #ifdef ESP32 - if (WiFi.disconnect(true)) { - _stopping = true; - } + if (WiFi.disconnect(true)) { + _stopping = true; + } #elif defined(ESP8266) - WiFi.disconnect(true); + WiFi.disconnect(true); #endif } void WiFiSettingsService::loop() { - unsigned long currentMillis = millis(); - if (!_lastConnectionAttempt || (unsigned long)(currentMillis - _lastConnectionAttempt) >= WIFI_RECONNECTION_DELAY) { - _lastConnectionAttempt = currentMillis; - manageSTA(); - } + unsigned long currentMillis = millis(); + if (!_lastConnectionAttempt || (unsigned long)(currentMillis - _lastConnectionAttempt) >= WIFI_RECONNECTION_DELAY) { + _lastConnectionAttempt = currentMillis; + manageSTA(); + } } void WiFiSettingsService::manageSTA() { - // Abort if already connected, or if we have no SSID - if (WiFi.isConnected() || _state.ssid.length() == 0) { - return; - } - // Connect or reconnect as required - if ((WiFi.getMode() & WIFI_STA) == 0) { - // Serial.println(F("Connecting to WiFi.")); - if (_state.staticIPConfig) { - // configure for static IP - WiFi.config(_state.localIP, _state.gatewayIP, _state.subnetMask, _state.dnsIP1, _state.dnsIP2); - } else { - // configure for DHCP -#ifdef ESP32 - WiFi.config(INADDR_NONE, INADDR_NONE, INADDR_NONE); - WiFi.setHostname(_state.hostname.c_str()); -#elif defined(ESP8266) - WiFi.config(INADDR_ANY, INADDR_ANY, INADDR_ANY); - WiFi.hostname(_state.hostname); -#endif + // Abort if already connected, or if we have no SSID + if (WiFi.isConnected() || _state.ssid.length() == 0) { + return; + } + // Connect or reconnect as required + if ((WiFi.getMode() & WIFI_STA) == 0) { + // Serial.println(F("Connecting to WiFi.")); + if (_state.staticIPConfig) { + // configure for static IP + WiFi.config(_state.localIP, _state.gatewayIP, _state.subnetMask, _state.dnsIP1, _state.dnsIP2); + } else { + // configure for DHCP +#ifdef ESP32 + WiFi.config(INADDR_NONE, INADDR_NONE, INADDR_NONE); +#elif defined(ESP8266) + WiFi.config(INADDR_ANY, INADDR_ANY, INADDR_ANY); +#endif + } + // set hostname +#ifdef ESP32 + WiFi.setHostname(_state.hostname.c_str()); +#elif defined(ESP8266) + WiFi.hostname(_state.hostname); +#endif + // attempt to connect to the network + WiFi.begin(_state.ssid.c_str(), _state.password.c_str()); } - // attempt to connect to the network - WiFi.begin(_state.ssid.c_str(), _state.password.c_str()); - } } #ifdef ESP32 void WiFiSettingsService::onStationModeDisconnected(WiFiEvent_t event, WiFiEventInfo_t info) { - WiFi.disconnect(true); + WiFi.disconnect(true); } void WiFiSettingsService::onStationModeStop(WiFiEvent_t event, WiFiEventInfo_t info) { - if (_stopping) { - _lastConnectionAttempt = 0; - _stopping = false; - } + if (_stopping) { + _lastConnectionAttempt = 0; + _stopping = false; + } } #elif defined(ESP8266) -void WiFiSettingsService::onStationModeDisconnected(const WiFiEventStationModeDisconnected& event) { - WiFi.disconnect(true); +void WiFiSettingsService::onStationModeDisconnected(const WiFiEventStationModeDisconnected & event) { + WiFi.disconnect(true); } #endif diff --git a/media/EMS-ESP_logo.png:Zone.Identifier b/media/EMS-ESP_logo.png:Zone.Identifier deleted file mode 100644 index 2dac2bc63..000000000 --- a/media/EMS-ESP_logo.png:Zone.Identifier +++ /dev/null @@ -1,3 +0,0 @@ -[ZoneTransfer] -LastWriterPackageFamilyName=Microsoft.MSPaint_8wekyb3d8bbwe -ZoneId=3 diff --git a/media/EMS-ESP_logo_dark.png:Zone.Identifier b/media/EMS-ESP_logo_dark.png:Zone.Identifier deleted file mode 100644 index 2dac2bc63..000000000 --- a/media/EMS-ESP_logo_dark.png:Zone.Identifier +++ /dev/null @@ -1,3 +0,0 @@ -[ZoneTransfer] -LastWriterPackageFamilyName=Microsoft.MSPaint_8wekyb3d8bbwe -ZoneId=3