mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-06 07:49:52 +03:00
more stable OTA uploads. disable UART and stop Mqtt during upload.
This commit is contained in:
@@ -178,7 +178,9 @@ The Web is based off Rick's awesome [esp8266-react](https://github.com/rjwats/es
|
|||||||
* `MqttStatus.cpp` added root["mqtt_fails"]
|
* `MqttStatus.cpp` added root["mqtt_fails"]
|
||||||
* `SecuritySettingsService.cpp` added version to the JWT payload
|
* `SecuritySettingsService.cpp` added version to the JWT payload
|
||||||
* `SecuritySettingsService.h` #include "../../src/version.h"
|
* `SecuritySettingsService.h` #include "../../src/version.h"
|
||||||
* `WiFiSettingsService.cpp` added WiFi.setOutputPower(20.0f)
|
* `WiFiSettingsService.cpp` added WiFi.setOutputPower(20.0f) - removed
|
||||||
|
* `OTASettingsService.h` added #include "../../src/system.h"
|
||||||
|
* `OTASettingsService.cpp` added call to emsesp::System::upload_status(true)
|
||||||
* `features.ini`: -D FT_NTP=0
|
* `features.ini`: -D FT_NTP=0
|
||||||
* `platformio.ini` using our own version
|
* `platformio.ini` using our own version
|
||||||
* `factory_settings.ini` modified with `ems-esp-neo` as password and `ems-esp` everywhere else
|
* `factory_settings.ini` modified with `ems-esp-neo` as password and `ems-esp` everywhere else
|
||||||
|
|||||||
@@ -1,46 +1,52 @@
|
|||||||
#include <OTASettingsService.h>
|
#include <OTASettingsService.h>
|
||||||
|
|
||||||
OTASettingsService::OTASettingsService(AsyncWebServer* server, FS* fs, SecurityManager* securityManager) :
|
OTASettingsService::OTASettingsService(AsyncWebServer * server, FS * fs, SecurityManager * securityManager)
|
||||||
_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
|
#ifdef ESP32
|
||||||
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)
|
#elif defined(ESP8266)
|
||||||
_onStationModeGotIPHandler =
|
_onStationModeGotIPHandler = WiFi.onStationModeGotIP(std::bind(&OTASettingsService::onStationModeGotIP, this, std::placeholders::_1));
|
||||||
WiFi.onStationModeGotIP(std::bind(&OTASettingsService::onStationModeGotIP, this, std::placeholders::_1));
|
|
||||||
#endif
|
#endif
|
||||||
addUpdateHandler([&](const String& originId) { configureArduinoOTA(); }, false);
|
addUpdateHandler([&](const String & originId) { configureArduinoOTA(); }, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void OTASettingsService::begin() {
|
void OTASettingsService::begin() {
|
||||||
_fsPersistence.readFromFS();
|
_fsPersistence.readFromFS();
|
||||||
configureArduinoOTA();
|
configureArduinoOTA();
|
||||||
}
|
}
|
||||||
|
|
||||||
void OTASettingsService::loop() {
|
void OTASettingsService::loop() {
|
||||||
if (_state.enabled && _arduinoOTA) {
|
if (_state.enabled && _arduinoOTA) {
|
||||||
_arduinoOTA->handle();
|
_arduinoOTA->handle();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void OTASettingsService::configureArduinoOTA() {
|
void OTASettingsService::configureArduinoOTA() {
|
||||||
if (_arduinoOTA) {
|
if (_arduinoOTA) {
|
||||||
#ifdef ESP32
|
#ifdef ESP32
|
||||||
_arduinoOTA->end();
|
_arduinoOTA->end();
|
||||||
#endif
|
#endif
|
||||||
delete _arduinoOTA;
|
delete _arduinoOTA;
|
||||||
_arduinoOTA = nullptr;
|
_arduinoOTA = nullptr;
|
||||||
}
|
}
|
||||||
if (_state.enabled) {
|
if (_state.enabled) {
|
||||||
// Serial.println(F("Starting OTA Update Service..."));
|
// 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([]() { Serial.println(F("Starting")); });
|
_arduinoOTA->onStart([]() {
|
||||||
_arduinoOTA->onEnd([]() { Serial.println(F("\r\nEnd")); });
|
// Serial.println(F("Starting"));
|
||||||
|
emsesp::System::upload_status(true);
|
||||||
|
});
|
||||||
|
_arduinoOTA->onEnd([]() {
|
||||||
|
// Serial.println(F("\r\nEnd"));
|
||||||
|
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)));
|
||||||
});
|
});
|
||||||
@@ -58,16 +64,16 @@ void OTASettingsService::configureArduinoOTA() {
|
|||||||
Serial.println(F("End Failed"));
|
Serial.println(F("End Failed"));
|
||||||
});
|
});
|
||||||
*/
|
*/
|
||||||
_arduinoOTA->begin();
|
_arduinoOTA->begin();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef ESP32
|
#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)
|
#elif defined(ESP8266)
|
||||||
void OTASettingsService::onStationModeGotIP(const WiFiEventStationModeGotIP& event) {
|
void OTASettingsService::onStationModeGotIP(const WiFiEventStationModeGotIP & event) {
|
||||||
configureArduinoOTA();
|
configureArduinoOTA();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -13,6 +13,8 @@
|
|||||||
#include <ArduinoOTA.h>
|
#include <ArduinoOTA.h>
|
||||||
#include <WiFiUdp.h>
|
#include <WiFiUdp.h>
|
||||||
|
|
||||||
|
#include "../../src/system.h" // proddy added
|
||||||
|
|
||||||
#ifndef FACTORY_OTA_PORT
|
#ifndef FACTORY_OTA_PORT
|
||||||
#define FACTORY_OTA_PORT 8266
|
#define FACTORY_OTA_PORT 8266
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user