Fix broken build under ESP32
Fix broken imports & standardise import style
This commit is contained in:
commit
14f50c1e31
@ -1,12 +1,12 @@
|
|||||||
#ifndef APStatus_h
|
#ifndef APStatus_h
|
||||||
#define APStatus_h
|
#define APStatus_h
|
||||||
|
|
||||||
#if defined(ESP8266)
|
#ifdef ESP32
|
||||||
|
#include <WiFi.h>
|
||||||
|
#include <AsyncTCP.h>
|
||||||
|
#elif defined(ESP8266)
|
||||||
#include <ESP8266WiFi.h>
|
#include <ESP8266WiFi.h>
|
||||||
#include <ESPAsyncTCP.h>
|
#include <ESPAsyncTCP.h>
|
||||||
#elif defined(ESP_PLATFORM)
|
|
||||||
#include <AsyncTCP.h>
|
|
||||||
#include <WiFi.h>
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <ArduinoJson.h>
|
#include <ArduinoJson.h>
|
||||||
|
@ -21,7 +21,7 @@ String ArduinoJsonJWT::getSecret() {
|
|||||||
String ArduinoJsonJWT::sign(String& payload) {
|
String ArduinoJsonJWT::sign(String& payload) {
|
||||||
unsigned char hmacResult[32];
|
unsigned char hmacResult[32];
|
||||||
{
|
{
|
||||||
#if defined(ESP_PLATFORM)
|
#ifdef ESP32
|
||||||
mbedtls_md_context_t ctx;
|
mbedtls_md_context_t ctx;
|
||||||
mbedtls_md_type_t md_type = MBEDTLS_MD_SHA256;
|
mbedtls_md_type_t md_type = MBEDTLS_MD_SHA256;
|
||||||
mbedtls_md_init(&ctx);
|
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_update(&ctx, (unsigned char*)payload.c_str(), payload.length());
|
||||||
mbedtls_md_hmac_finish(&ctx, hmacResult);
|
mbedtls_md_hmac_finish(&ctx, hmacResult);
|
||||||
mbedtls_md_free(&ctx);
|
mbedtls_md_free(&ctx);
|
||||||
#else
|
#elif defined(ESP8266)
|
||||||
br_hmac_key_context keyCtx;
|
br_hmac_key_context keyCtx;
|
||||||
br_hmac_key_init(&keyCtx, &br_sha256_vtable, _secret.c_str(), _secret.length());
|
br_hmac_key_init(&keyCtx, &br_sha256_vtable, _secret.c_str(), _secret.length());
|
||||||
br_hmac_context hmacCtx;
|
br_hmac_context hmacCtx;
|
||||||
@ -93,12 +93,12 @@ void ArduinoJsonJWT::parseJWT(String jwt, JsonDocument& jsonDocument) {
|
|||||||
String ArduinoJsonJWT::encode(const char* cstr, int inputLen) {
|
String ArduinoJsonJWT::encode(const char* cstr, int inputLen) {
|
||||||
// prepare encoder
|
// prepare encoder
|
||||||
base64_encodestate _state;
|
base64_encodestate _state;
|
||||||
#if defined(ESP8266)
|
#ifdef ESP32
|
||||||
base64_init_encodestate_nonewlines(&_state);
|
|
||||||
size_t encodedLength = base64_encode_expected_len_nonewlines(inputLen) + 1;
|
|
||||||
#elif defined(ESP_PLATFORM)
|
|
||||||
base64_init_encodestate(&_state);
|
base64_init_encodestate(&_state);
|
||||||
size_t encodedLength = base64_encode_expected_len(inputLen) + 1;
|
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
|
#endif
|
||||||
// prepare buffer of correct length, returning an empty string on failure
|
// prepare buffer of correct length, returning an empty string on failure
|
||||||
char* buffer = (char*)malloc(encodedLength * sizeof(char));
|
char* buffer = (char*)malloc(encodedLength * sizeof(char));
|
||||||
|
@ -5,9 +5,10 @@
|
|||||||
#include <ArduinoJson.h>
|
#include <ArduinoJson.h>
|
||||||
#include <libb64/cdecode.h>
|
#include <libb64/cdecode.h>
|
||||||
#include <libb64/cencode.h>
|
#include <libb64/cencode.h>
|
||||||
#if defined(ESP_PLATFORM)
|
|
||||||
|
#ifdef ESP32
|
||||||
#include <mbedtls/md.h>
|
#include <mbedtls/md.h>
|
||||||
#else
|
#elif defined(ESP8266)
|
||||||
#include <bearssl/bearssl_hmac.h>
|
#include <bearssl/bearssl_hmac.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -3,19 +3,19 @@
|
|||||||
|
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
|
|
||||||
#if defined(ESP8266)
|
#ifdef ESP32
|
||||||
#include <ESP8266WiFi.h>
|
#include <WiFi.h>
|
||||||
#include <ESPAsyncTCP.h>
|
|
||||||
#elif defined(ESP_PLATFORM)
|
|
||||||
#include <AsyncTCP.h>
|
#include <AsyncTCP.h>
|
||||||
#include <SPIFFS.h>
|
#include <SPIFFS.h>
|
||||||
#include <WiFi.h>
|
#elif defined(ESP8266)
|
||||||
|
#include <ESP8266WiFi.h>
|
||||||
|
#include <ESPAsyncTCP.h>
|
||||||
|
#include <FS.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <APSettingsService.h>
|
#include <APSettingsService.h>
|
||||||
#include <APStatus.h>
|
#include <APStatus.h>
|
||||||
#include <AuthenticationService.h>
|
#include <AuthenticationService.h>
|
||||||
#include <FS.h>
|
|
||||||
#include <NTPSettingsService.h>
|
#include <NTPSettingsService.h>
|
||||||
#include <NTPStatus.h>
|
#include <NTPStatus.h>
|
||||||
#include <OTASettingsService.h>
|
#include <OTASettingsService.h>
|
||||||
|
@ -2,19 +2,18 @@
|
|||||||
|
|
||||||
NTPSettingsService::NTPSettingsService(AsyncWebServer* server, FS* fs, SecurityManager* securityManager) :
|
NTPSettingsService::NTPSettingsService(AsyncWebServer* server, FS* fs, SecurityManager* securityManager) :
|
||||||
AdminSettingsService(server, fs, securityManager, NTP_SETTINGS_SERVICE_PATH, NTP_SETTINGS_FILE) {
|
AdminSettingsService(server, fs, securityManager, NTP_SETTINGS_SERVICE_PATH, NTP_SETTINGS_FILE) {
|
||||||
#if defined(ESP8266)
|
#ifdef ESP32
|
||||||
_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)
|
|
||||||
WiFi.onEvent(
|
WiFi.onEvent(
|
||||||
std::bind(&NTPSettingsService::onStationModeDisconnected, this, std::placeholders::_1, std::placeholders::_2),
|
std::bind(&NTPSettingsService::onStationModeDisconnected, this, std::placeholders::_1, std::placeholders::_2),
|
||||||
WiFiEvent_t::SYSTEM_EVENT_STA_DISCONNECTED);
|
WiFiEvent_t::SYSTEM_EVENT_STA_DISCONNECTED);
|
||||||
WiFi.onEvent(std::bind(&NTPSettingsService::onStationModeGotIP, this, std::placeholders::_1, std::placeholders::_2),
|
WiFi.onEvent(std::bind(&NTPSettingsService::onStationModeGotIP, this, std::placeholders::_1, std::placeholders::_2),
|
||||||
WiFiEvent_t::SYSTEM_EVENT_STA_GOT_IP);
|
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
|
#endif
|
||||||
|
|
||||||
NTP.onNTPSyncEvent([this](NTPSyncEvent_t ntpEvent) {
|
NTP.onNTPSyncEvent([this](NTPSyncEvent_t ntpEvent) {
|
||||||
_ntpEvent = ntpEvent;
|
_ntpEvent = ntpEvent;
|
||||||
_syncEventTriggered = true;
|
_syncEventTriggered = true;
|
||||||
@ -68,18 +67,7 @@ void NTPSettingsService::onConfigUpdated() {
|
|||||||
_reconfigureNTP = true;
|
_reconfigureNTP = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(ESP8266)
|
#ifdef ESP32
|
||||||
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)
|
|
||||||
void NTPSettingsService::onStationModeGotIP(WiFiEvent_t event, WiFiEventInfo_t info) {
|
void NTPSettingsService::onStationModeGotIP(WiFiEvent_t event, WiFiEventInfo_t info) {
|
||||||
Serial.printf("Got IP address, starting NTP Synchronization\n");
|
Serial.printf("Got IP address, starting NTP Synchronization\n");
|
||||||
_reconfigureNTP = true;
|
_reconfigureNTP = true;
|
||||||
@ -90,6 +78,17 @@ void NTPSettingsService::onStationModeDisconnected(WiFiEvent_t event, WiFiEventI
|
|||||||
_reconfigureNTP = false;
|
_reconfigureNTP = false;
|
||||||
NTP.stop();
|
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
|
#endif
|
||||||
|
|
||||||
void NTPSettingsService::configureNTP() {
|
void NTPSettingsService::configureNTP() {
|
||||||
|
@ -37,15 +37,15 @@ class NTPSettingsService : public AdminSettingsService {
|
|||||||
bool _syncEventTriggered = false;
|
bool _syncEventTriggered = false;
|
||||||
NTPSyncEvent_t _ntpEvent;
|
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 _onStationModeDisconnectedHandler;
|
||||||
WiFiEventHandler _onStationModeGotIPHandler;
|
WiFiEventHandler _onStationModeGotIPHandler;
|
||||||
|
|
||||||
void onStationModeGotIP(const WiFiEventStationModeGotIP& event);
|
void onStationModeGotIP(const WiFiEventStationModeGotIP& event);
|
||||||
void onStationModeDisconnected(const WiFiEventStationModeDisconnected& 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
|
#endif
|
||||||
|
|
||||||
void configureNTP();
|
void configureNTP();
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
#ifndef NTPStatus_h
|
#ifndef NTPStatus_h
|
||||||
#define NTPStatus_h
|
#define NTPStatus_h
|
||||||
|
|
||||||
#if defined(ESP8266)
|
#ifdef ESP32
|
||||||
|
#include <WiFi.h>
|
||||||
|
#include <AsyncTCP.h>
|
||||||
|
#elif defined(ESP8266)
|
||||||
#include <ESP8266WiFi.h>
|
#include <ESP8266WiFi.h>
|
||||||
#include <ESPAsyncTCP.h>
|
#include <ESPAsyncTCP.h>
|
||||||
#elif defined(ESP_PLATFORM)
|
|
||||||
#include <AsyncTCP.h>
|
|
||||||
#include <WiFi.h>
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <ArduinoJson.h>
|
#include <ArduinoJson.h>
|
||||||
|
@ -2,12 +2,12 @@
|
|||||||
|
|
||||||
OTASettingsService::OTASettingsService(AsyncWebServer* server, FS* fs, SecurityManager* securityManager) :
|
OTASettingsService::OTASettingsService(AsyncWebServer* server, FS* fs, SecurityManager* securityManager) :
|
||||||
AdminSettingsService(server, fs, securityManager, OTA_SETTINGS_SERVICE_PATH, OTA_SETTINGS_FILE) {
|
AdminSettingsService(server, fs, securityManager, OTA_SETTINGS_SERVICE_PATH, OTA_SETTINGS_FILE) {
|
||||||
#if defined(ESP8266)
|
#ifdef ESP32
|
||||||
_onStationModeGotIPHandler =
|
|
||||||
WiFi.onStationModeGotIP(std::bind(&OTASettingsService::onStationModeGotIP, this, std::placeholders::_1));
|
|
||||||
#elif defined(ESP_PLATFORM)
|
|
||||||
WiFi.onEvent(std::bind(&OTASettingsService::onStationModeGotIP, this, std::placeholders::_1, std::placeholders::_2),
|
WiFi.onEvent(std::bind(&OTASettingsService::onStationModeGotIP, this, std::placeholders::_1, std::placeholders::_2),
|
||||||
WiFiEvent_t::SYSTEM_EVENT_STA_GOT_IP);
|
WiFiEvent_t::SYSTEM_EVENT_STA_GOT_IP);
|
||||||
|
#elif defined(ESP8266)
|
||||||
|
_onStationModeGotIPHandler =
|
||||||
|
WiFi.onStationModeGotIP(std::bind(&OTASettingsService::onStationModeGotIP, this, std::placeholders::_1));
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -43,7 +43,7 @@ void OTASettingsService::writeToJsonObject(JsonObject& root) {
|
|||||||
|
|
||||||
void OTASettingsService::configureArduinoOTA() {
|
void OTASettingsService::configureArduinoOTA() {
|
||||||
if (_arduinoOTA) {
|
if (_arduinoOTA) {
|
||||||
#if defined(ESP_PLATFORM)
|
#ifdef ESP32
|
||||||
_arduinoOTA->end();
|
_arduinoOTA->end();
|
||||||
#endif
|
#endif
|
||||||
delete _arduinoOTA;
|
delete _arduinoOTA;
|
||||||
@ -75,13 +75,12 @@ void OTASettingsService::configureArduinoOTA() {
|
|||||||
_arduinoOTA->begin();
|
_arduinoOTA->begin();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#ifdef ESP32
|
||||||
#if defined(ESP8266)
|
|
||||||
void OTASettingsService::onStationModeGotIP(const WiFiEventStationModeGotIP& event) {
|
|
||||||
configureArduinoOTA();
|
|
||||||
}
|
|
||||||
#elif defined(ESP_PLATFORM)
|
|
||||||
void OTASettingsService::onStationModeGotIP(WiFiEvent_t event, WiFiEventInfo_t info) {
|
void OTASettingsService::onStationModeGotIP(WiFiEvent_t event, WiFiEventInfo_t info) {
|
||||||
configureArduinoOTA();
|
configureArduinoOTA();
|
||||||
}
|
}
|
||||||
|
#elif defined(ESP8266)
|
||||||
|
void OTASettingsService::onStationModeGotIP(const WiFiEventStationModeGotIP& event) {
|
||||||
|
configureArduinoOTA();
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -3,10 +3,10 @@
|
|||||||
|
|
||||||
#include <AdminSettingsService.h>
|
#include <AdminSettingsService.h>
|
||||||
|
|
||||||
#if defined(ESP8266)
|
#ifdef ESP32
|
||||||
#include <ESP8266mDNS.h>
|
|
||||||
#elif defined(ESP_PLATFORM)
|
|
||||||
#include <ESPmDNS.h>
|
#include <ESPmDNS.h>
|
||||||
|
#elif defined(ESP8266)
|
||||||
|
#include <ESP8266mDNS.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <ArduinoOTA.h>
|
#include <ArduinoOTA.h>
|
||||||
@ -38,12 +38,11 @@ class OTASettingsService : public AdminSettingsService {
|
|||||||
String _password;
|
String _password;
|
||||||
|
|
||||||
void configureArduinoOTA();
|
void configureArduinoOTA();
|
||||||
|
#ifdef ESP32
|
||||||
#if defined(ESP8266)
|
void onStationModeGotIP(WiFiEvent_t event, WiFiEventInfo_t info);
|
||||||
|
#elif defined(ESP8266)
|
||||||
WiFiEventHandler _onStationModeGotIPHandler;
|
WiFiEventHandler _onStationModeGotIPHandler;
|
||||||
void onStationModeGotIP(const WiFiEventStationModeGotIP& event);
|
void onStationModeGotIP(const WiFiEventStationModeGotIP& event);
|
||||||
#elif defined(ESP_PLATFORM)
|
|
||||||
void onStationModeGotIP(WiFiEvent_t event, WiFiEventInfo_t info);
|
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -9,10 +9,10 @@ RestartService::RestartService(AsyncWebServer* server, SecurityManager* security
|
|||||||
|
|
||||||
void RestartService::restart(AsyncWebServerRequest* request) {
|
void RestartService::restart(AsyncWebServerRequest* request) {
|
||||||
request->onDisconnect([]() {
|
request->onDisconnect([]() {
|
||||||
#if defined(ESP8266)
|
#ifdef ESP32
|
||||||
ESP.reset();
|
|
||||||
#elif defined(ESP_PLATFORM)
|
|
||||||
ESP.restart();
|
ESP.restart();
|
||||||
|
#elif defined(ESP8266)
|
||||||
|
ESP.reset();
|
||||||
#endif
|
#endif
|
||||||
});
|
});
|
||||||
request->send(200);
|
request->send(200);
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
#ifndef RestartService_h
|
#ifndef RestartService_h
|
||||||
#define RestartService_h
|
#define RestartService_h
|
||||||
|
|
||||||
#if defined(ESP8266)
|
#ifdef ESP32
|
||||||
|
#include <WiFi.h>
|
||||||
|
#include <AsyncTCP.h>
|
||||||
|
#elif defined(ESP8266)
|
||||||
#include <ESP8266WiFi.h>
|
#include <ESP8266WiFi.h>
|
||||||
#include <ESPAsyncTCP.h>
|
#include <ESPAsyncTCP.h>
|
||||||
#elif defined(ESP_PLATFORM)
|
|
||||||
#include <AsyncTCP.h>
|
|
||||||
#include <WiFi.h>
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <ESPAsyncWebServer.h>
|
#include <ESPAsyncWebServer.h>
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
#ifndef SettingsService_h
|
#ifndef SettingsService_h
|
||||||
#define SettingsService_h
|
#define SettingsService_h
|
||||||
|
|
||||||
#if defined(ESP8266)
|
#ifdef ESP32
|
||||||
|
#include <WiFi.h>
|
||||||
|
#include <AsyncTCP.h>
|
||||||
|
#elif defined(ESP8266)
|
||||||
#include <ESP8266WiFi.h>
|
#include <ESP8266WiFi.h>
|
||||||
#include <ESPAsyncTCP.h>
|
#include <ESPAsyncTCP.h>
|
||||||
#elif defined(ESP_PLATFORM)
|
|
||||||
#include <AsyncTCP.h>
|
|
||||||
#include <WiFi.h>
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <ArduinoJson.h>
|
#include <ArduinoJson.h>
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
#ifndef Service_h
|
#ifndef Service_h
|
||||||
#define Service_h
|
#define Service_h
|
||||||
|
|
||||||
#if defined(ESP8266)
|
#ifdef ESP32
|
||||||
|
#include <WiFi.h>
|
||||||
|
#include <AsyncTCP.h>
|
||||||
|
#elif defined(ESP8266)
|
||||||
#include <ESP8266WiFi.h>
|
#include <ESP8266WiFi.h>
|
||||||
#include <ESPAsyncTCP.h>
|
#include <ESPAsyncTCP.h>
|
||||||
#elif defined(ESP_PLATFORM)
|
|
||||||
#include <AsyncTCP.h>
|
|
||||||
#include <WiFi.h>
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <ArduinoJson.h>
|
#include <ArduinoJson.h>
|
||||||
|
@ -10,10 +10,10 @@ SystemStatus::SystemStatus(AsyncWebServer* server, SecurityManager* securityMana
|
|||||||
void SystemStatus::systemStatus(AsyncWebServerRequest* request) {
|
void SystemStatus::systemStatus(AsyncWebServerRequest* request) {
|
||||||
AsyncJsonResponse* response = new AsyncJsonResponse(false, MAX_ESP_STATUS_SIZE);
|
AsyncJsonResponse* response = new AsyncJsonResponse(false, MAX_ESP_STATUS_SIZE);
|
||||||
JsonObject root = response->getRoot();
|
JsonObject root = response->getRoot();
|
||||||
#if defined(ESP8266)
|
#ifdef ESP32
|
||||||
root["esp_platform"] = "esp8266";
|
|
||||||
#elif defined(ESP_PLATFORM)
|
|
||||||
root["esp_platform"] = "esp32";
|
root["esp_platform"] = "esp32";
|
||||||
|
#elif defined(ESP8266)
|
||||||
|
root["esp_platform"] = "esp8266";
|
||||||
#endif
|
#endif
|
||||||
root["cpu_freq_mhz"] = ESP.getCpuFreqMHz();
|
root["cpu_freq_mhz"] = ESP.getCpuFreqMHz();
|
||||||
root["free_heap"] = ESP.getFreeHeap();
|
root["free_heap"] = ESP.getFreeHeap();
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
#ifndef SystemStatus_h
|
#ifndef SystemStatus_h
|
||||||
#define SystemStatus_h
|
#define SystemStatus_h
|
||||||
|
|
||||||
#if defined(ESP8266)
|
#ifdef ESP32
|
||||||
|
#include <WiFi.h>
|
||||||
|
#include <AsyncTCP.h>
|
||||||
|
#elif defined(ESP8266)
|
||||||
#include <ESP8266WiFi.h>
|
#include <ESP8266WiFi.h>
|
||||||
#include <ESPAsyncTCP.h>
|
#include <ESPAsyncTCP.h>
|
||||||
#elif defined(ESP_PLATFORM)
|
|
||||||
#include <AsyncTCP.h>
|
|
||||||
#include <WiFi.h>
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <ArduinoJson.h>
|
#include <ArduinoJson.h>
|
||||||
|
@ -31,10 +31,10 @@ void WiFiScanner::listNetworks(AsyncWebServerRequest* request) {
|
|||||||
network["ssid"] = WiFi.SSID(i);
|
network["ssid"] = WiFi.SSID(i);
|
||||||
network["bssid"] = WiFi.BSSIDstr(i);
|
network["bssid"] = WiFi.BSSIDstr(i);
|
||||||
network["channel"] = WiFi.channel(i);
|
network["channel"] = WiFi.channel(i);
|
||||||
#if defined(ESP8266)
|
#ifdef ESP32
|
||||||
network["encryption_type"] = convertEncryptionType(WiFi.encryptionType(i));
|
|
||||||
#elif defined(ESP_PLATFORM)
|
|
||||||
network["encryption_type"] = (uint8_t)WiFi.encryptionType(i);
|
network["encryption_type"] = (uint8_t)WiFi.encryptionType(i);
|
||||||
|
#elif defined(ESP8266)
|
||||||
|
network["encryption_type"] = convertEncryptionType(WiFi.encryptionType(i));
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
response->setLength();
|
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.
|
* Convert encryption type to standard used by ESP32 rather than the translated form which the esp8266 libaries expose.
|
||||||
*
|
*
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
#ifndef WiFiScanner_h
|
#ifndef WiFiScanner_h
|
||||||
#define WiFiScanner_h
|
#define WiFiScanner_h
|
||||||
|
|
||||||
#if defined(ESP8266)
|
#ifdef ESP32
|
||||||
|
#include <WiFi.h>
|
||||||
|
#include <AsyncTCP.h>
|
||||||
|
#elif defined(ESP8266)
|
||||||
#include <ESP8266WiFi.h>
|
#include <ESP8266WiFi.h>
|
||||||
#include <ESPAsyncTCP.h>
|
#include <ESPAsyncTCP.h>
|
||||||
#elif defined(ESP_PLATFORM)
|
|
||||||
#include <AsyncTCP.h>
|
|
||||||
#include <WiFi.h>
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <ArduinoJson.h>
|
#include <ArduinoJson.h>
|
||||||
@ -28,7 +28,7 @@ class WiFiScanner {
|
|||||||
void scanNetworks(AsyncWebServerRequest* request);
|
void scanNetworks(AsyncWebServerRequest* request);
|
||||||
void listNetworks(AsyncWebServerRequest* request);
|
void listNetworks(AsyncWebServerRequest* request);
|
||||||
|
|
||||||
#if defined(ESP8266)
|
#ifdef ESP8266
|
||||||
uint8_t convertEncryptionType(uint8_t encryptionType);
|
uint8_t convertEncryptionType(uint8_t encryptionType);
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
@ -11,17 +11,16 @@ WiFiSettingsService::WiFiSettingsService(AsyncWebServer* server, FS* fs, Securit
|
|||||||
// Disable WiFi config persistance and auto reconnect
|
// Disable WiFi config persistance and auto reconnect
|
||||||
WiFi.persistent(false);
|
WiFi.persistent(false);
|
||||||
WiFi.setAutoReconnect(false);
|
WiFi.setAutoReconnect(false);
|
||||||
|
#ifdef ESP32
|
||||||
#if defined(ESP8266)
|
|
||||||
_onStationModeDisconnectedHandler = WiFi.onStationModeDisconnected(
|
|
||||||
std::bind(&WiFiSettingsService::onStationModeDisconnected, this, std::placeholders::_1));
|
|
||||||
#elif defined(ESP_PLATFORM)
|
|
||||||
// Init the wifi driver on ESP32
|
// Init the wifi driver on ESP32
|
||||||
WiFi.mode(WIFI_MODE_MAX);
|
WiFi.mode(WIFI_MODE_MAX);
|
||||||
WiFi.mode(WIFI_MODE_NULL);
|
WiFi.mode(WIFI_MODE_NULL);
|
||||||
WiFi.onEvent(
|
WiFi.onEvent(
|
||||||
std::bind(&WiFiSettingsService::onStationModeDisconnected, this, std::placeholders::_1, std::placeholders::_2),
|
std::bind(&WiFiSettingsService::onStationModeDisconnected, this, std::placeholders::_1, std::placeholders::_2),
|
||||||
WiFiEvent_t::SYSTEM_EVENT_STA_DISCONNECTED);
|
WiFiEvent_t::SYSTEM_EVENT_STA_DISCONNECTED);
|
||||||
|
#elif defined(ESP8266)
|
||||||
|
_onStationModeDisconnectedHandler = WiFi.onStationModeDisconnected(
|
||||||
|
std::bind(&WiFiSettingsService::onStationModeDisconnected, this, std::placeholders::_1));
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -120,12 +119,12 @@ void WiFiSettingsService::manageSTA() {
|
|||||||
WiFi.config(_localIP, _gatewayIP, _subnetMask, _dnsIP1, _dnsIP2);
|
WiFi.config(_localIP, _gatewayIP, _subnetMask, _dnsIP1, _dnsIP2);
|
||||||
} else {
|
} else {
|
||||||
// configure for DHCP
|
// configure for DHCP
|
||||||
#if defined(ESP8266)
|
#ifdef ESP32
|
||||||
WiFi.config(INADDR_ANY, INADDR_ANY, INADDR_ANY);
|
|
||||||
WiFi.hostname(_hostname);
|
|
||||||
#elif defined(ESP_PLATFORM)
|
|
||||||
WiFi.config(INADDR_NONE, INADDR_NONE, INADDR_NONE);
|
WiFi.config(INADDR_NONE, INADDR_NONE, INADDR_NONE);
|
||||||
WiFi.setHostname(_hostname.c_str());
|
WiFi.setHostname(_hostname.c_str());
|
||||||
|
#elif defined(ESP8266)
|
||||||
|
WiFi.config(INADDR_ANY, INADDR_ANY, INADDR_ANY);
|
||||||
|
WiFi.hostname(_hostname);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
// attempt to connect to the network
|
// attempt to connect to the network
|
||||||
@ -133,12 +132,12 @@ void WiFiSettingsService::manageSTA() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(ESP8266)
|
#ifdef ESP32
|
||||||
void WiFiSettingsService::onStationModeDisconnected(const WiFiEventStationModeDisconnected& event) {
|
|
||||||
WiFi.disconnect(true);
|
|
||||||
}
|
|
||||||
#elif defined(ESP_PLATFORM)
|
|
||||||
void WiFiSettingsService::onStationModeDisconnected(WiFiEvent_t event, WiFiEventInfo_t info) {
|
void WiFiSettingsService::onStationModeDisconnected(WiFiEvent_t event, WiFiEventInfo_t info) {
|
||||||
WiFi.disconnect(true);
|
WiFi.disconnect(true);
|
||||||
}
|
}
|
||||||
|
#elif defined(ESP8266)
|
||||||
|
void WiFiSettingsService::onStationModeDisconnected(const WiFiEventStationModeDisconnected& event) {
|
||||||
|
WiFi.disconnect(true);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -38,11 +38,11 @@ class WiFiSettingsService : public AdminSettingsService {
|
|||||||
IPAddress _dnsIP1;
|
IPAddress _dnsIP1;
|
||||||
IPAddress _dnsIP2;
|
IPAddress _dnsIP2;
|
||||||
|
|
||||||
#if defined(ESP8266)
|
#ifdef ESP32
|
||||||
|
void onStationModeDisconnected(WiFiEvent_t event, WiFiEventInfo_t info);
|
||||||
|
#elif defined(ESP8266)
|
||||||
WiFiEventHandler _onStationModeDisconnectedHandler;
|
WiFiEventHandler _onStationModeDisconnectedHandler;
|
||||||
void onStationModeDisconnected(const WiFiEventStationModeDisconnected& event);
|
void onStationModeDisconnected(const WiFiEventStationModeDisconnected& event);
|
||||||
#elif defined(ESP_PLATFORM)
|
|
||||||
void onStationModeDisconnected(WiFiEvent_t event, WiFiEventInfo_t info);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void readIP(JsonObject& root, String key, IPAddress& _ip);
|
void readIP(JsonObject& root, String key, IPAddress& _ip);
|
||||||
|
@ -5,18 +5,34 @@ WiFiStatus::WiFiStatus(AsyncWebServer* server, SecurityManager* securityManager)
|
|||||||
HTTP_GET,
|
HTTP_GET,
|
||||||
securityManager->wrapRequest(std::bind(&WiFiStatus::wifiStatus, this, std::placeholders::_1),
|
securityManager->wrapRequest(std::bind(&WiFiStatus::wifiStatus, this, std::placeholders::_1),
|
||||||
AuthenticationPredicates::IS_AUTHENTICATED));
|
AuthenticationPredicates::IS_AUTHENTICATED));
|
||||||
#if defined(ESP8266)
|
#ifdef ESP32
|
||||||
_onStationModeConnectedHandler = WiFi.onStationModeConnected(onStationModeConnected);
|
|
||||||
_onStationModeDisconnectedHandler = WiFi.onStationModeDisconnected(onStationModeDisconnected);
|
|
||||||
_onStationModeGotIPHandler = WiFi.onStationModeGotIP(onStationModeGotIP);
|
|
||||||
#elif defined(ESP_PLATFORM)
|
|
||||||
WiFi.onEvent(onStationModeConnected, WiFiEvent_t::SYSTEM_EVENT_STA_CONNECTED);
|
WiFi.onEvent(onStationModeConnected, WiFiEvent_t::SYSTEM_EVENT_STA_CONNECTED);
|
||||||
WiFi.onEvent(onStationModeDisconnected, WiFiEvent_t::SYSTEM_EVENT_STA_DISCONNECTED);
|
WiFi.onEvent(onStationModeDisconnected, WiFiEvent_t::SYSTEM_EVENT_STA_DISCONNECTED);
|
||||||
WiFi.onEvent(onStationModeGotIP, WiFiEvent_t::SYSTEM_EVENT_STA_GOT_IP);
|
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
|
#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) {
|
void WiFiStatus::onStationModeConnected(const WiFiEventStationModeConnected& event) {
|
||||||
Serial.print("WiFi Connected. SSID=");
|
Serial.print("WiFi Connected. SSID=");
|
||||||
Serial.println(event.ssid);
|
Serial.println(event.ssid);
|
||||||
@ -33,22 +49,6 @@ void WiFiStatus::onStationModeGotIP(const WiFiEventStationModeGotIP& event) {
|
|||||||
Serial.print(", hostName=");
|
Serial.print(", hostName=");
|
||||||
Serial.println(WiFi.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
|
#endif
|
||||||
|
|
||||||
void WiFiStatus::wifiStatus(AsyncWebServerRequest* request) {
|
void WiFiStatus::wifiStatus(AsyncWebServerRequest* request) {
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
#ifndef WiFiStatus_h
|
#ifndef WiFiStatus_h
|
||||||
#define WiFiStatus_h
|
#define WiFiStatus_h
|
||||||
|
|
||||||
#if defined(ESP8266)
|
#ifdef ESP32
|
||||||
|
#include <WiFi.h>
|
||||||
|
#include <AsyncTCP.h>
|
||||||
|
#elif defined(ESP8266)
|
||||||
#include <ESP8266WiFi.h>
|
#include <ESP8266WiFi.h>
|
||||||
#include <ESPAsyncTCP.h>
|
#include <ESPAsyncTCP.h>
|
||||||
#elif defined(ESP_PLATFORM)
|
|
||||||
#include <AsyncTCP.h>
|
|
||||||
#include <WiFi.h>
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <ArduinoJson.h>
|
#include <ArduinoJson.h>
|
||||||
@ -23,7 +23,12 @@ class WiFiStatus {
|
|||||||
WiFiStatus(AsyncWebServer* server, SecurityManager* securityManager);
|
WiFiStatus(AsyncWebServer* server, SecurityManager* securityManager);
|
||||||
|
|
||||||
private:
|
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
|
// handler refrences for logging important WiFi events over serial
|
||||||
WiFiEventHandler _onStationModeConnectedHandler;
|
WiFiEventHandler _onStationModeConnectedHandler;
|
||||||
WiFiEventHandler _onStationModeDisconnectedHandler;
|
WiFiEventHandler _onStationModeDisconnectedHandler;
|
||||||
@ -32,11 +37,6 @@ class WiFiStatus {
|
|||||||
static void onStationModeConnected(const WiFiEventStationModeConnected& event);
|
static void onStationModeConnected(const WiFiEventStationModeConnected& event);
|
||||||
static void onStationModeDisconnected(const WiFiEventStationModeDisconnected& event);
|
static void onStationModeDisconnected(const WiFiEventStationModeDisconnected& event);
|
||||||
static void onStationModeGotIP(const WiFiEventStationModeGotIP& 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
|
#endif
|
||||||
|
|
||||||
void wifiStatus(AsyncWebServerRequest* request);
|
void wifiStatus(AsyncWebServerRequest* request);
|
||||||
|
Loading…
Reference in New Issue
Block a user