mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-06 15:59:52 +03:00
minor cleanup
This commit is contained in:
@@ -6,11 +6,7 @@ OTASettingsService::OTASettingsService(AsyncWebServer * server, FS * fs, Securit
|
|||||||
: _httpEndpoint(OTASettings::read, OTASettings::update, this, server, OTA_SETTINGS_SERVICE_PATH, securityManager)
|
: _httpEndpoint(OTASettings::read, OTASettings::update, this, server, OTA_SETTINGS_SERVICE_PATH, securityManager)
|
||||||
, _fsPersistence(OTASettings::read, OTASettings::update, this, fs, OTA_SETTINGS_FILE)
|
, _fsPersistence(OTASettings::read, OTASettings::update, this, fs, OTA_SETTINGS_FILE)
|
||||||
, _arduinoOTA(nullptr) {
|
, _arduinoOTA(nullptr) {
|
||||||
#ifdef ESP32
|
|
||||||
WiFi.onEvent(std::bind(&OTASettingsService::onStationModeGotIP, this, std::placeholders::_1, std::placeholders::_2), WiFiEvent_t::SYSTEM_EVENT_STA_GOT_IP);
|
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
|
|
||||||
addUpdateHandler([&](const String & originId) { configureArduinoOTA(); }, false);
|
addUpdateHandler([&](const String & originId) { configureArduinoOTA(); }, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -34,47 +30,38 @@ void OTASettingsService::configureArduinoOTA() {
|
|||||||
_arduinoOTA = nullptr;
|
_arduinoOTA = nullptr;
|
||||||
}
|
}
|
||||||
if (_state.enabled) {
|
if (_state.enabled) {
|
||||||
// Serial.println(F("Starting OTA Update Service..."));
|
|
||||||
_arduinoOTA = new ArduinoOTAClass;
|
_arduinoOTA = new ArduinoOTAClass;
|
||||||
_arduinoOTA->setPort(_state.port);
|
_arduinoOTA->setPort(_state.port);
|
||||||
_arduinoOTA->setPassword(_state.password.c_str());
|
_arduinoOTA->setPassword(_state.password.c_str());
|
||||||
|
|
||||||
_arduinoOTA->onStart([]() {
|
_arduinoOTA->onStart([]() {
|
||||||
// Serial.println(F("Starting"));
|
Serial.println(F("Starting"));
|
||||||
emsesp::EMSESP::system_.upload_status(true);
|
emsesp::EMSESP::system_.upload_status(true);
|
||||||
});
|
});
|
||||||
_arduinoOTA->onEnd([]() {
|
_arduinoOTA->onEnd([]() {
|
||||||
// Serial.println(F("\r\nEnd"));
|
Serial.println(F("\r\nEnd"));
|
||||||
emsesp::EMSESP::system_.upload_status(false);
|
emsesp::EMSESP::system_.upload_status(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
// _arduinoOTA->onProgress([](unsigned int progress, unsigned int total) {
|
_arduinoOTA->onProgress([](unsigned int progress, unsigned int total) { Serial.printf_P(PSTR("Progress: %u%%\r\n"), (progress / (total / 100))); });
|
||||||
// Serial.printf_P(PSTR("Progress: %u%%\r\n"), (progress / (total / 100)));
|
_arduinoOTA->onError([](ota_error_t error) {
|
||||||
// });
|
Serial.printf("Error[%u]: ", error);
|
||||||
// _arduinoOTA->onError([](ota_error_t error) {
|
if (error == OTA_AUTH_ERROR)
|
||||||
// Serial.printf("Error[%u]: ", error);
|
Serial.println(F("Auth Failed"));
|
||||||
// if (error == OTA_AUTH_ERROR)
|
else if (error == OTA_BEGIN_ERROR)
|
||||||
// Serial.println(F("Auth Failed"));
|
Serial.println(F("Begin Failed"));
|
||||||
// else if (error == OTA_BEGIN_ERROR)
|
else if (error == OTA_CONNECT_ERROR)
|
||||||
// Serial.println(F("Begin Failed"));
|
Serial.println(F("Connect Failed"));
|
||||||
// else if (error == OTA_CONNECT_ERROR)
|
else if (error == OTA_RECEIVE_ERROR)
|
||||||
// Serial.println(F("Connect Failed"));
|
Serial.println(F("Receive Failed"));
|
||||||
// else if (error == OTA_RECEIVE_ERROR)
|
else if (error == OTA_END_ERROR)
|
||||||
// Serial.println(F("Receive Failed"));
|
Serial.println(F("End Failed"));
|
||||||
// else if (error == OTA_END_ERROR)
|
});
|
||||||
// Serial.println(F("End Failed"));
|
|
||||||
// });
|
|
||||||
|
|
||||||
_arduinoOTA->begin();
|
_arduinoOTA->begin();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef ESP32
|
|
||||||
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
|
|
||||||
|
|||||||
@@ -4,11 +4,7 @@
|
|||||||
#include <HttpEndpoint.h>
|
#include <HttpEndpoint.h>
|
||||||
#include <FSPersistence.h>
|
#include <FSPersistence.h>
|
||||||
|
|
||||||
#ifdef ESP32
|
|
||||||
#include <ESPmDNS.h>
|
#include <ESPmDNS.h>
|
||||||
#elif defined(ESP8266)
|
|
||||||
#include <ESP8266mDNS.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <ArduinoOTA.h>
|
#include <ArduinoOTA.h>
|
||||||
#include <WiFiUdp.h>
|
#include <WiFiUdp.h>
|
||||||
@@ -61,12 +57,7 @@ class OTASettingsService : public StatefulService<OTASettings> {
|
|||||||
ArduinoOTAClass * _arduinoOTA;
|
ArduinoOTAClass * _arduinoOTA;
|
||||||
|
|
||||||
void configureArduinoOTA();
|
void configureArduinoOTA();
|
||||||
#ifdef ESP32
|
|
||||||
void onStationModeGotIP(WiFiEvent_t event, WiFiEventInfo_t info);
|
void onStationModeGotIP(WiFiEvent_t event, WiFiEventInfo_t info);
|
||||||
#elif defined(ESP8266)
|
|
||||||
WiFiEventHandler _onStationModeGotIPHandler;
|
|
||||||
void onStationModeGotIP(const WiFiEventStationModeGotIP & event);
|
|
||||||
#endif
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // end OTASettingsService_h
|
#endif // end OTASettingsService_h
|
||||||
|
|||||||
Reference in New Issue
Block a user