stop all other processes when updating via OTA for speed

This commit is contained in:
Paul
2019-07-01 09:15:38 +02:00
parent 6fb30c7352
commit 533a3b3408
2 changed files with 16 additions and 4 deletions

View File

@@ -73,6 +73,7 @@ MyESP::MyESP() {
_ota_pre_callback = NULL; _ota_pre_callback = NULL;
_ota_post_callback = NULL; _ota_post_callback = NULL;
_ota_doing_update = false;
_suspendOutput = false; _suspendOutput = false;
@@ -470,6 +471,8 @@ void MyESP::_OTACallback() {
// stop the web server // stop the web server
webServer.close(); webServer.close();
_ota_doing_update = true;
if (_ota_pre_callback) { if (_ota_pre_callback) {
(_ota_pre_callback)(); // call custom function (_ota_pre_callback)(); // call custom function
} }
@@ -487,9 +490,11 @@ void MyESP::_ota_setup() {
ArduinoOTA.onStart([this]() { _OTACallback(); }); ArduinoOTA.onStart([this]() { _OTACallback(); });
ArduinoOTA.onEnd([this]() { ArduinoOTA.onEnd([this]() {
myDebug_P(PSTR("[OTA] Done, restarting...")); myDebug_P(PSTR("[OTA] Done, restarting..."));
_ota_doing_update = false;
_deferredReset(500, CUSTOM_RESET_OTA); _deferredReset(500, CUSTOM_RESET_OTA);
}); });
/*
ArduinoOTA.onProgress([this](unsigned int progress, unsigned int total) { ArduinoOTA.onProgress([this](unsigned int progress, unsigned int total) {
static unsigned int _progOld; static unsigned int _progOld;
unsigned int _prog = (progress / (total / 100)); unsigned int _prog = (progress / (total / 100));
@@ -498,6 +503,7 @@ void MyESP::_ota_setup() {
_progOld = _prog; _progOld = _prog;
} }
}); });
*/
ArduinoOTA.onError([this](ota_error_t error) { ArduinoOTA.onError([this](ota_error_t error) {
if (error == OTA_AUTH_ERROR) if (error == OTA_AUTH_ERROR)
@@ -2186,6 +2192,13 @@ void MyESP::_bootupSequence() {
* Loop. This is called as often as possible and it handles wifi, telnet, mqtt etc * Loop. This is called as often as possible and it handles wifi, telnet, mqtt etc
*/ */
void MyESP::loop() { void MyESP::loop() {
jw.loop(); // WiFi
ArduinoOTA.handle(); // OTA
if (_ota_doing_update) {
return; // quit if in the middle of an update
}
_calculateLoad(); _calculateLoad();
_systemCheckLoop(); _systemCheckLoop();
_heartbeatCheck(); _heartbeatCheck();
@@ -2197,9 +2210,7 @@ void MyESP::loop() {
_telnetHandle(); _telnetHandle();
} }
jw.loop(); // WiFi _mqttConnect(); // MQTT
ArduinoOTA.handle(); // OTA
_mqttConnect(); // MQTT
yield(); // ...and breath yield(); // ...and breath
} }

View File

@@ -9,7 +9,7 @@
#ifndef MyEMS_h #ifndef MyEMS_h
#define MyEMS_h #define MyEMS_h
#define MYESP_VERSION "1.1.19" #define MYESP_VERSION "1.1.20"
#include <ArduinoJson.h> #include <ArduinoJson.h>
#include <ArduinoOTA.h> #include <ArduinoOTA.h>
@@ -335,6 +335,7 @@ class MyESP {
ota_callback_f _ota_post_callback; ota_callback_f _ota_post_callback;
void _ota_setup(); void _ota_setup();
void _OTACallback(); void _OTACallback();
bool _ota_doing_update;
// crash // crash
void _eeprom_setup(); void _eeprom_setup();