From 62f3d3fc7a636cef6f8dc9ef39d3a85d7143a06d Mon Sep 17 00:00:00 2001 From: Rick Watson Date: Tue, 24 Dec 2019 11:19:19 +0000 Subject: [PATCH] fix broken imports under ESP32 use ESP32 rather than ESP_PLATFORM - it's ambigious standardise to ifdef ESP32 elif defined(ESP8266) use ifdef over if defined where possible --- lib/framework/APStatus.h | 8 ++--- lib/framework/ArduinoJsonJWT.cpp | 12 ++++---- lib/framework/ArduinoJsonJWT.h | 5 +-- lib/framework/ESP8266React.h | 12 ++++---- lib/framework/NTPSettingsService.cpp | 37 +++++++++++----------- lib/framework/NTPSettingsService.h | 8 ++--- lib/framework/NTPStatus.h | 8 ++--- lib/framework/OTASettingsService.cpp | 21 ++++++------- lib/framework/OTASettingsService.h | 13 ++++---- lib/framework/RestartService.cpp | 6 ++-- lib/framework/RestartService.h | 8 ++--- lib/framework/SettingsService.h | 8 ++--- lib/framework/SimpleService.h | 8 ++--- lib/framework/SystemStatus.cpp | 6 ++-- lib/framework/SystemStatus.h | 8 ++--- lib/framework/WiFiScanner.cpp | 8 ++--- lib/framework/WiFiScanner.h | 10 +++--- lib/framework/WiFiSettingsService.cpp | 27 ++++++++-------- lib/framework/WiFiSettingsService.h | 6 ++-- lib/framework/WiFiStatus.cpp | 44 +++++++++++++-------------- lib/framework/WiFiStatus.h | 20 ++++++------ 21 files changed, 140 insertions(+), 143 deletions(-) diff --git a/lib/framework/APStatus.h b/lib/framework/APStatus.h index 3e069a5..54f90e9 100644 --- a/lib/framework/APStatus.h +++ b/lib/framework/APStatus.h @@ -1,12 +1,12 @@ #ifndef APStatus_h #define APStatus_h -#if defined(ESP8266) +#ifdef ESP32 +#include +#include +#elif defined(ESP8266) #include #include -#elif defined(ESP_PLATFORM) -#include -#include #endif #include diff --git a/lib/framework/ArduinoJsonJWT.cpp b/lib/framework/ArduinoJsonJWT.cpp index 3bba9fe..8b449e1 100644 --- a/lib/framework/ArduinoJsonJWT.cpp +++ b/lib/framework/ArduinoJsonJWT.cpp @@ -21,7 +21,7 @@ String ArduinoJsonJWT::getSecret() { String ArduinoJsonJWT::sign(String& payload) { unsigned char hmacResult[32]; { -#if defined(ESP_PLATFORM) +#ifdef ESP32 mbedtls_md_context_t ctx; mbedtls_md_type_t md_type = MBEDTLS_MD_SHA256; mbedtls_md_init(&ctx); @@ -30,7 +30,7 @@ String ArduinoJsonJWT::sign(String& payload) { mbedtls_md_hmac_update(&ctx, (unsigned char*)payload.c_str(), payload.length()); mbedtls_md_hmac_finish(&ctx, hmacResult); mbedtls_md_free(&ctx); -#else +#elif defined(ESP8266) br_hmac_key_context keyCtx; br_hmac_key_init(&keyCtx, &br_sha256_vtable, _secret.c_str(), _secret.length()); br_hmac_context hmacCtx; @@ -93,12 +93,12 @@ void ArduinoJsonJWT::parseJWT(String jwt, JsonDocument& jsonDocument) { String ArduinoJsonJWT::encode(const char* cstr, int inputLen) { // prepare encoder base64_encodestate _state; -#if defined(ESP8266) - base64_init_encodestate_nonewlines(&_state); - size_t encodedLength = base64_encode_expected_len_nonewlines(inputLen) + 1; -#elif defined(ESP_PLATFORM) +#ifdef ESP32 base64_init_encodestate(&_state); size_t encodedLength = base64_encode_expected_len(inputLen) + 1; +#elif defined(ESP8266) + base64_init_encodestate_nonewlines(&_state); + size_t encodedLength = base64_encode_expected_len_nonewlines(inputLen) + 1; #endif // prepare buffer of correct length, returning an empty string on failure char* buffer = (char*)malloc(encodedLength * sizeof(char)); diff --git a/lib/framework/ArduinoJsonJWT.h b/lib/framework/ArduinoJsonJWT.h index e61764e..beeedc0 100644 --- a/lib/framework/ArduinoJsonJWT.h +++ b/lib/framework/ArduinoJsonJWT.h @@ -5,9 +5,10 @@ #include #include #include -#if defined(ESP_PLATFORM) + +#ifdef ESP32 #include -#else +#elif defined(ESP8266) #include #endif diff --git a/lib/framework/ESP8266React.h b/lib/framework/ESP8266React.h index 21f297a..d76ac14 100644 --- a/lib/framework/ESP8266React.h +++ b/lib/framework/ESP8266React.h @@ -3,19 +3,19 @@ #include -#if defined(ESP8266) -#include -#include -#elif defined(ESP_PLATFORM) +#ifdef ESP32 +#include #include #include -#include +#elif defined(ESP8266) +#include +#include +#include #endif #include #include #include -#include #include #include #include diff --git a/lib/framework/NTPSettingsService.cpp b/lib/framework/NTPSettingsService.cpp index 548f218..f727375 100644 --- a/lib/framework/NTPSettingsService.cpp +++ b/lib/framework/NTPSettingsService.cpp @@ -2,19 +2,18 @@ NTPSettingsService::NTPSettingsService(AsyncWebServer* server, FS* fs, SecurityManager* securityManager) : AdminSettingsService(server, fs, securityManager, NTP_SETTINGS_SERVICE_PATH, NTP_SETTINGS_FILE) { -#if defined(ESP8266) - _onStationModeDisconnectedHandler = WiFi.onStationModeDisconnected( - std::bind(&NTPSettingsService::onStationModeDisconnected, this, std::placeholders::_1)); - _onStationModeGotIPHandler = - WiFi.onStationModeGotIP(std::bind(&NTPSettingsService::onStationModeGotIP, this, std::placeholders::_1)); -#elif defined(ESP_PLATFORM) +#ifdef ESP32 WiFi.onEvent( std::bind(&NTPSettingsService::onStationModeDisconnected, this, std::placeholders::_1, std::placeholders::_2), WiFiEvent_t::SYSTEM_EVENT_STA_DISCONNECTED); WiFi.onEvent(std::bind(&NTPSettingsService::onStationModeGotIP, this, std::placeholders::_1, std::placeholders::_2), WiFiEvent_t::SYSTEM_EVENT_STA_GOT_IP); +#elif defined(ESP8266) + _onStationModeDisconnectedHandler = WiFi.onStationModeDisconnected( + std::bind(&NTPSettingsService::onStationModeDisconnected, this, std::placeholders::_1)); + _onStationModeGotIPHandler = + WiFi.onStationModeGotIP(std::bind(&NTPSettingsService::onStationModeGotIP, this, std::placeholders::_1)); #endif - NTP.onNTPSyncEvent([this](NTPSyncEvent_t ntpEvent) { _ntpEvent = ntpEvent; _syncEventTriggered = true; @@ -68,18 +67,7 @@ void NTPSettingsService::onConfigUpdated() { _reconfigureNTP = true; } -#if defined(ESP8266) -void NTPSettingsService::onStationModeGotIP(const WiFiEventStationModeGotIP& event) { - Serial.printf("Got IP address, starting NTP Synchronization\n"); - _reconfigureNTP = true; -} - -void NTPSettingsService::onStationModeDisconnected(const WiFiEventStationModeDisconnected& event) { - Serial.printf("WiFi connection dropped, stopping NTP.\n"); - _reconfigureNTP = false; - NTP.stop(); -} -#elif defined(ESP_PLATFORM) +#ifdef ESP32 void NTPSettingsService::onStationModeGotIP(WiFiEvent_t event, WiFiEventInfo_t info) { Serial.printf("Got IP address, starting NTP Synchronization\n"); _reconfigureNTP = true; @@ -90,6 +78,17 @@ void NTPSettingsService::onStationModeDisconnected(WiFiEvent_t event, WiFiEventI _reconfigureNTP = false; NTP.stop(); } +#elif defined(ESP8266) +void NTPSettingsService::onStationModeGotIP(const WiFiEventStationModeGotIP& event) { + Serial.printf("Got IP address, starting NTP Synchronization\n"); + _reconfigureNTP = true; +} + +void NTPSettingsService::onStationModeDisconnected(const WiFiEventStationModeDisconnected& event) { + Serial.printf("WiFi connection dropped, stopping NTP.\n"); + _reconfigureNTP = false; + NTP.stop(); +} #endif void NTPSettingsService::configureNTP() { diff --git a/lib/framework/NTPSettingsService.h b/lib/framework/NTPSettingsService.h index d155be4..6c49d1e 100644 --- a/lib/framework/NTPSettingsService.h +++ b/lib/framework/NTPSettingsService.h @@ -37,15 +37,15 @@ class NTPSettingsService : public AdminSettingsService { bool _syncEventTriggered = false; NTPSyncEvent_t _ntpEvent; -#if defined(ESP8266) +#ifdef ESP32 + void onStationModeGotIP(WiFiEvent_t event, WiFiEventInfo_t info); + void onStationModeDisconnected(WiFiEvent_t event, WiFiEventInfo_t info); +#elif defined(ESP8266) WiFiEventHandler _onStationModeDisconnectedHandler; WiFiEventHandler _onStationModeGotIPHandler; void onStationModeGotIP(const WiFiEventStationModeGotIP& event); void onStationModeDisconnected(const WiFiEventStationModeDisconnected& event); -#elif defined(ESP_PLATFORM) - void onStationModeGotIP(WiFiEvent_t event, WiFiEventInfo_t info); - void onStationModeDisconnected(WiFiEvent_t event, WiFiEventInfo_t info); #endif void configureNTP(); diff --git a/lib/framework/NTPStatus.h b/lib/framework/NTPStatus.h index 0a7f99e..52ff6d7 100644 --- a/lib/framework/NTPStatus.h +++ b/lib/framework/NTPStatus.h @@ -1,12 +1,12 @@ #ifndef NTPStatus_h #define NTPStatus_h -#if defined(ESP8266) +#ifdef ESP32 +#include +#include +#elif defined(ESP8266) #include #include -#elif defined(ESP_PLATFORM) -#include -#include #endif #include diff --git a/lib/framework/OTASettingsService.cpp b/lib/framework/OTASettingsService.cpp index d0bbc0a..76c85bc 100644 --- a/lib/framework/OTASettingsService.cpp +++ b/lib/framework/OTASettingsService.cpp @@ -2,12 +2,12 @@ OTASettingsService::OTASettingsService(AsyncWebServer* server, FS* fs, SecurityManager* securityManager) : AdminSettingsService(server, fs, securityManager, OTA_SETTINGS_SERVICE_PATH, OTA_SETTINGS_FILE) { -#if defined(ESP8266) - _onStationModeGotIPHandler = - WiFi.onStationModeGotIP(std::bind(&OTASettingsService::onStationModeGotIP, this, std::placeholders::_1)); -#elif defined(ESP_PLATFORM) +#ifdef ESP32 WiFi.onEvent(std::bind(&OTASettingsService::onStationModeGotIP, this, std::placeholders::_1, std::placeholders::_2), WiFiEvent_t::SYSTEM_EVENT_STA_GOT_IP); +#elif defined(ESP8266) + _onStationModeGotIPHandler = + WiFi.onStationModeGotIP(std::bind(&OTASettingsService::onStationModeGotIP, this, std::placeholders::_1)); #endif } @@ -43,7 +43,7 @@ void OTASettingsService::writeToJsonObject(JsonObject& root) { void OTASettingsService::configureArduinoOTA() { if (_arduinoOTA) { -#if defined(ESP_PLATFORM) +#ifdef ESP32 _arduinoOTA->end(); #endif delete _arduinoOTA; @@ -75,13 +75,12 @@ void OTASettingsService::configureArduinoOTA() { _arduinoOTA->begin(); } } - -#if defined(ESP8266) -void OTASettingsService::onStationModeGotIP(const WiFiEventStationModeGotIP& event) { - configureArduinoOTA(); -} -#elif defined(ESP_PLATFORM) +#ifdef ESP32 void OTASettingsService::onStationModeGotIP(WiFiEvent_t event, WiFiEventInfo_t info) { configureArduinoOTA(); } +#elif defined(ESP8266) +void OTASettingsService::onStationModeGotIP(const WiFiEventStationModeGotIP& event) { + configureArduinoOTA(); +} #endif diff --git a/lib/framework/OTASettingsService.h b/lib/framework/OTASettingsService.h index 36ed2aa..1de9e4b 100644 --- a/lib/framework/OTASettingsService.h +++ b/lib/framework/OTASettingsService.h @@ -3,10 +3,10 @@ #include -#if defined(ESP8266) -#include -#elif defined(ESP_PLATFORM) +#ifdef ESP32 #include +#elif defined(ESP8266) +#include #endif #include @@ -38,12 +38,11 @@ class OTASettingsService : public AdminSettingsService { String _password; void configureArduinoOTA(); - -#if defined(ESP8266) +#ifdef ESP32 + void onStationModeGotIP(WiFiEvent_t event, WiFiEventInfo_t info); +#elif defined(ESP8266) WiFiEventHandler _onStationModeGotIPHandler; void onStationModeGotIP(const WiFiEventStationModeGotIP& event); -#elif defined(ESP_PLATFORM) - void onStationModeGotIP(WiFiEvent_t event, WiFiEventInfo_t info); #endif }; diff --git a/lib/framework/RestartService.cpp b/lib/framework/RestartService.cpp index 235cf61..8ef5751 100644 --- a/lib/framework/RestartService.cpp +++ b/lib/framework/RestartService.cpp @@ -9,10 +9,10 @@ RestartService::RestartService(AsyncWebServer* server, SecurityManager* security void RestartService::restart(AsyncWebServerRequest* request) { request->onDisconnect([]() { -#if defined(ESP8266) - ESP.reset(); -#elif defined(ESP_PLATFORM) +#ifdef ESP32 ESP.restart(); +#elif defined(ESP8266) + ESP.reset(); #endif }); request->send(200); diff --git a/lib/framework/RestartService.h b/lib/framework/RestartService.h index 51adf75..ca2cff2 100644 --- a/lib/framework/RestartService.h +++ b/lib/framework/RestartService.h @@ -1,12 +1,12 @@ #ifndef RestartService_h #define RestartService_h -#if defined(ESP8266) +#ifdef ESP32 +#include +#include +#elif defined(ESP8266) #include #include -#elif defined(ESP_PLATFORM) -#include -#include #endif #include diff --git a/lib/framework/SettingsService.h b/lib/framework/SettingsService.h index a9f1110..1d964fe 100644 --- a/lib/framework/SettingsService.h +++ b/lib/framework/SettingsService.h @@ -1,12 +1,12 @@ #ifndef SettingsService_h #define SettingsService_h -#if defined(ESP8266) +#ifdef ESP32 +#include +#include +#elif defined(ESP8266) #include #include -#elif defined(ESP_PLATFORM) -#include -#include #endif #include diff --git a/lib/framework/SimpleService.h b/lib/framework/SimpleService.h index 555826b..2cc29e2 100644 --- a/lib/framework/SimpleService.h +++ b/lib/framework/SimpleService.h @@ -1,12 +1,12 @@ #ifndef Service_h #define Service_h -#if defined(ESP8266) +#ifdef ESP32 +#include +#include +#elif defined(ESP8266) #include #include -#elif defined(ESP_PLATFORM) -#include -#include #endif #include diff --git a/lib/framework/SystemStatus.cpp b/lib/framework/SystemStatus.cpp index a3e6013..6784489 100644 --- a/lib/framework/SystemStatus.cpp +++ b/lib/framework/SystemStatus.cpp @@ -10,10 +10,10 @@ SystemStatus::SystemStatus(AsyncWebServer* server, SecurityManager* securityMana void SystemStatus::systemStatus(AsyncWebServerRequest* request) { AsyncJsonResponse* response = new AsyncJsonResponse(false, MAX_ESP_STATUS_SIZE); JsonObject root = response->getRoot(); -#if defined(ESP8266) - root["esp_platform"] = "esp8266"; -#elif defined(ESP_PLATFORM) +#ifdef ESP32 root["esp_platform"] = "esp32"; +#elif defined(ESP8266) + root["esp_platform"] = "esp8266"; #endif root["cpu_freq_mhz"] = ESP.getCpuFreqMHz(); root["free_heap"] = ESP.getFreeHeap(); diff --git a/lib/framework/SystemStatus.h b/lib/framework/SystemStatus.h index cbb5db5..aa44623 100644 --- a/lib/framework/SystemStatus.h +++ b/lib/framework/SystemStatus.h @@ -1,12 +1,12 @@ #ifndef SystemStatus_h #define SystemStatus_h -#if defined(ESP8266) +#ifdef ESP32 +#include +#include +#elif defined(ESP8266) #include #include -#elif defined(ESP_PLATFORM) -#include -#include #endif #include diff --git a/lib/framework/WiFiScanner.cpp b/lib/framework/WiFiScanner.cpp index 434d579..7b33189 100644 --- a/lib/framework/WiFiScanner.cpp +++ b/lib/framework/WiFiScanner.cpp @@ -31,10 +31,10 @@ void WiFiScanner::listNetworks(AsyncWebServerRequest* request) { network["ssid"] = WiFi.SSID(i); network["bssid"] = WiFi.BSSIDstr(i); network["channel"] = WiFi.channel(i); -#if defined(ESP8266) - network["encryption_type"] = convertEncryptionType(WiFi.encryptionType(i)); -#elif defined(ESP_PLATFORM) +#ifdef ESP32 network["encryption_type"] = (uint8_t)WiFi.encryptionType(i); +#elif defined(ESP8266) + network["encryption_type"] = convertEncryptionType(WiFi.encryptionType(i)); #endif } response->setLength(); @@ -46,7 +46,7 @@ void WiFiScanner::listNetworks(AsyncWebServerRequest* request) { } } -#if defined(ESP8266) +#ifdef ESP8266 /* * Convert encryption type to standard used by ESP32 rather than the translated form which the esp8266 libaries expose. * diff --git a/lib/framework/WiFiScanner.h b/lib/framework/WiFiScanner.h index 8a4ea3d..f0f1724 100644 --- a/lib/framework/WiFiScanner.h +++ b/lib/framework/WiFiScanner.h @@ -1,12 +1,12 @@ #ifndef WiFiScanner_h #define WiFiScanner_h -#if defined(ESP8266) +#ifdef ESP32 +#include +#include +#elif defined(ESP8266) #include #include -#elif defined(ESP_PLATFORM) -#include -#include #endif #include @@ -28,7 +28,7 @@ class WiFiScanner { void scanNetworks(AsyncWebServerRequest* request); void listNetworks(AsyncWebServerRequest* request); -#if defined(ESP8266) +#ifdef ESP8266 uint8_t convertEncryptionType(uint8_t encryptionType); #endif }; diff --git a/lib/framework/WiFiSettingsService.cpp b/lib/framework/WiFiSettingsService.cpp index d7eb966..9b70146 100644 --- a/lib/framework/WiFiSettingsService.cpp +++ b/lib/framework/WiFiSettingsService.cpp @@ -11,17 +11,16 @@ WiFiSettingsService::WiFiSettingsService(AsyncWebServer* server, FS* fs, Securit // Disable WiFi config persistance and auto reconnect WiFi.persistent(false); WiFi.setAutoReconnect(false); - -#if defined(ESP8266) - _onStationModeDisconnectedHandler = WiFi.onStationModeDisconnected( - std::bind(&WiFiSettingsService::onStationModeDisconnected, this, std::placeholders::_1)); -#elif defined(ESP_PLATFORM) +#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); +#elif defined(ESP8266) + _onStationModeDisconnectedHandler = WiFi.onStationModeDisconnected( + std::bind(&WiFiSettingsService::onStationModeDisconnected, this, std::placeholders::_1)); #endif } @@ -120,12 +119,12 @@ void WiFiSettingsService::manageSTA() { WiFi.config(_localIP, _gatewayIP, _subnetMask, _dnsIP1, _dnsIP2); } else { // configure for DHCP -#if defined(ESP8266) - WiFi.config(INADDR_ANY, INADDR_ANY, INADDR_ANY); - WiFi.hostname(_hostname); -#elif defined(ESP_PLATFORM) +#ifdef ESP32 WiFi.config(INADDR_NONE, INADDR_NONE, INADDR_NONE); WiFi.setHostname(_hostname.c_str()); +#elif defined(ESP8266) + WiFi.config(INADDR_ANY, INADDR_ANY, INADDR_ANY); + WiFi.hostname(_hostname); #endif } // attempt to connect to the network @@ -133,12 +132,12 @@ void WiFiSettingsService::manageSTA() { } } -#if defined(ESP8266) -void WiFiSettingsService::onStationModeDisconnected(const WiFiEventStationModeDisconnected& event) { - WiFi.disconnect(true); -} -#elif defined(ESP_PLATFORM) +#ifdef ESP32 void WiFiSettingsService::onStationModeDisconnected(WiFiEvent_t event, WiFiEventInfo_t info) { WiFi.disconnect(true); } +#elif defined(ESP8266) +void WiFiSettingsService::onStationModeDisconnected(const WiFiEventStationModeDisconnected& event) { + WiFi.disconnect(true); +} #endif diff --git a/lib/framework/WiFiSettingsService.h b/lib/framework/WiFiSettingsService.h index 2a5898e..102f571 100644 --- a/lib/framework/WiFiSettingsService.h +++ b/lib/framework/WiFiSettingsService.h @@ -38,11 +38,11 @@ class WiFiSettingsService : public AdminSettingsService { IPAddress _dnsIP1; IPAddress _dnsIP2; -#if defined(ESP8266) +#ifdef ESP32 + void onStationModeDisconnected(WiFiEvent_t event, WiFiEventInfo_t info); +#elif defined(ESP8266) WiFiEventHandler _onStationModeDisconnectedHandler; void onStationModeDisconnected(const WiFiEventStationModeDisconnected& event); -#elif defined(ESP_PLATFORM) - void onStationModeDisconnected(WiFiEvent_t event, WiFiEventInfo_t info); #endif void readIP(JsonObject& root, String key, IPAddress& _ip); diff --git a/lib/framework/WiFiStatus.cpp b/lib/framework/WiFiStatus.cpp index 8f19c55..9971e01 100644 --- a/lib/framework/WiFiStatus.cpp +++ b/lib/framework/WiFiStatus.cpp @@ -5,18 +5,34 @@ WiFiStatus::WiFiStatus(AsyncWebServer* server, SecurityManager* securityManager) HTTP_GET, securityManager->wrapRequest(std::bind(&WiFiStatus::wifiStatus, this, std::placeholders::_1), AuthenticationPredicates::IS_AUTHENTICATED)); -#if defined(ESP8266) - _onStationModeConnectedHandler = WiFi.onStationModeConnected(onStationModeConnected); - _onStationModeDisconnectedHandler = WiFi.onStationModeDisconnected(onStationModeDisconnected); - _onStationModeGotIPHandler = WiFi.onStationModeGotIP(onStationModeGotIP); -#elif defined(ESP_PLATFORM) +#ifdef ESP32 WiFi.onEvent(onStationModeConnected, WiFiEvent_t::SYSTEM_EVENT_STA_CONNECTED); WiFi.onEvent(onStationModeDisconnected, WiFiEvent_t::SYSTEM_EVENT_STA_DISCONNECTED); WiFi.onEvent(onStationModeGotIP, WiFiEvent_t::SYSTEM_EVENT_STA_GOT_IP); +#elif defined(ESP8266) + _onStationModeConnectedHandler = WiFi.onStationModeConnected(onStationModeConnected); + _onStationModeDisconnectedHandler = WiFi.onStationModeDisconnected(onStationModeDisconnected); + _onStationModeGotIPHandler = WiFi.onStationModeGotIP(onStationModeGotIP); #endif } -#if defined(ESP8266) +#ifdef ESP32 +void WiFiStatus::onStationModeConnected(WiFiEvent_t event, WiFiEventInfo_t info) { + Serial.println("WiFi Connected."); +} + +void WiFiStatus::onStationModeDisconnected(WiFiEvent_t event, WiFiEventInfo_t info) { + Serial.print("WiFi Disconnected. Reason code="); + Serial.println(info.disconnected.reason); +} + +void WiFiStatus::onStationModeGotIP(WiFiEvent_t event, WiFiEventInfo_t info) { + Serial.print("WiFi Got IP. localIP="); + Serial.print(WiFi.localIP().toString()); + Serial.print(", hostName="); + Serial.println(WiFi.getHostname()); +} +#elif defined(ESP8266) void WiFiStatus::onStationModeConnected(const WiFiEventStationModeConnected& event) { Serial.print("WiFi Connected. SSID="); Serial.println(event.ssid); @@ -33,22 +49,6 @@ void WiFiStatus::onStationModeGotIP(const WiFiEventStationModeGotIP& event) { Serial.print(", hostName="); Serial.println(WiFi.hostname()); } -#elif defined(ESP_PLATFORM) -void WiFiStatus::onStationModeConnected(WiFiEvent_t event, WiFiEventInfo_t info) { - Serial.println("WiFi Connected."); -} - -void WiFiStatus::onStationModeDisconnected(WiFiEvent_t event, WiFiEventInfo_t info) { - Serial.print("WiFi Disconnected. Reason code="); - Serial.println(info.disconnected.reason); -} - -void WiFiStatus::onStationModeGotIP(WiFiEvent_t event, WiFiEventInfo_t info) { - Serial.print("WiFi Got IP. localIP="); - Serial.print(WiFi.localIP().toString()); - Serial.print(", hostName="); - Serial.println(WiFi.getHostname()); -} #endif void WiFiStatus::wifiStatus(AsyncWebServerRequest* request) { diff --git a/lib/framework/WiFiStatus.h b/lib/framework/WiFiStatus.h index a7c3f5c..197bd64 100644 --- a/lib/framework/WiFiStatus.h +++ b/lib/framework/WiFiStatus.h @@ -1,12 +1,12 @@ #ifndef WiFiStatus_h #define WiFiStatus_h -#if defined(ESP8266) +#ifdef ESP32 +#include +#include +#elif defined(ESP8266) #include #include -#elif defined(ESP_PLATFORM) -#include -#include #endif #include @@ -23,7 +23,12 @@ class WiFiStatus { WiFiStatus(AsyncWebServer* server, SecurityManager* securityManager); private: -#if defined(ESP8266) +#ifdef ESP32 + // static functions for logging WiFi events to the UART + static void onStationModeConnected(WiFiEvent_t event, WiFiEventInfo_t info); + static void onStationModeDisconnected(WiFiEvent_t event, WiFiEventInfo_t info); + static void onStationModeGotIP(WiFiEvent_t event, WiFiEventInfo_t info); +#elif defined(ESP8266) // handler refrences for logging important WiFi events over serial WiFiEventHandler _onStationModeConnectedHandler; WiFiEventHandler _onStationModeDisconnectedHandler; @@ -32,11 +37,6 @@ class WiFiStatus { static void onStationModeConnected(const WiFiEventStationModeConnected& event); static void onStationModeDisconnected(const WiFiEventStationModeDisconnected& event); static void onStationModeGotIP(const WiFiEventStationModeGotIP& event); -#elif defined(ESP_PLATFORM) - // static functions for logging WiFi events to the UART - static void onStationModeConnected(WiFiEvent_t event, WiFiEventInfo_t info); - static void onStationModeDisconnected(WiFiEvent_t event, WiFiEventInfo_t info); - static void onStationModeGotIP(WiFiEvent_t event, WiFiEventInfo_t info); #endif void wifiStatus(AsyncWebServerRequest* request);