mirror of
https://github.com/HASwitchPlate/openHASP.git
synced 2025-07-24 11:46:34 +00:00
Progress OTA messages
This commit is contained in:
parent
99e12e46c7
commit
15a61188fd
@ -10,26 +10,13 @@
|
||||
|
||||
#define F_OTA_URL F("otaurl")
|
||||
|
||||
std::string otaUrl = "http://10.1.0.3";
|
||||
int8_t prevUpdateValue = -1;
|
||||
std::string otaUrl = "http://10.1.0.3";
|
||||
int8_t otaPrecentageComplete = -1;
|
||||
|
||||
void otaProgress(uint8_t val)
|
||||
void otaProgress()
|
||||
{
|
||||
String type;
|
||||
uint8_t deltaValue;
|
||||
|
||||
if(ArduinoOTA.getCommand() == U_FLASH) {
|
||||
type = F("Firmware");
|
||||
deltaValue = 4;
|
||||
} else { // U_SPIFFS
|
||||
deltaValue = 2;
|
||||
type = F("Filesystem");
|
||||
}
|
||||
|
||||
if(val - prevUpdateValue >= deltaValue) {
|
||||
debugPrintln(String(F("OTA: ")) + type + F(" update in progress... ") + val + "%");
|
||||
prevUpdateValue = val;
|
||||
}
|
||||
debugPrintln(String(F("OTA: ")) + (ArduinoOTA.getCommand() == U_FLASH ? F("Firmware") : F("Filesystem")) +
|
||||
F(" update in progress... ") + otaPrecentageComplete + "%");
|
||||
}
|
||||
|
||||
void otaSetup(JsonObject settings)
|
||||
@ -53,23 +40,24 @@ void otaSetup(JsonObject settings)
|
||||
|
||||
debugPrintln(F("OTA: Start update"));
|
||||
dispatchCommand("page 0");
|
||||
otaPrecentageComplete = 0;
|
||||
// haspSetAttr("p[0].b[1].txt", "\"ESP OTA Update\"");
|
||||
});
|
||||
ArduinoOTA.onEnd([]() {
|
||||
prevUpdateValue = -1;
|
||||
otaProgress(100);
|
||||
otaPrecentageComplete = 100;
|
||||
otaProgress();
|
||||
otaPrecentageComplete = -1;
|
||||
dispatchPage("0");
|
||||
// haspSetAttr("p[0].b[1].txt", "\"ESP OTA Update\\rComplete!\"");
|
||||
dispatchReboot(true);
|
||||
});
|
||||
ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
|
||||
if(total != 0) {
|
||||
int8_t val = progress * 100 / total;
|
||||
otaProgress(val);
|
||||
}
|
||||
if(total != 0) otaPrecentageComplete = progress * 100 / total;
|
||||
|
||||
// haspSetAttr("p[0].b[1].txt", "\"ESP OTA Update\\rProgress: " + String(progress / (total / 100)) + "%\"");
|
||||
});
|
||||
ArduinoOTA.onError([](ota_error_t error) {
|
||||
otaPrecentageComplete = -1;
|
||||
debugPrintln(String(F("OTA: ERROR code ")) + String(error));
|
||||
if(error == OTA_AUTH_ERROR)
|
||||
debugPrintln(F("OTA: ERROR - Auth Failed"));
|
||||
@ -87,9 +75,15 @@ void otaSetup(JsonObject settings)
|
||||
});
|
||||
ArduinoOTA.begin();
|
||||
debugPrintln(F("OTA: Over the Air firmware update ready"));
|
||||
debugPrintln(F("OTA: Setup Complete"));
|
||||
}
|
||||
|
||||
void otaLoop(bool wifiIsConnected)
|
||||
void otaLoop()
|
||||
{
|
||||
ArduinoOTA.handle();
|
||||
}
|
||||
|
||||
void otaEverySecond()
|
||||
{
|
||||
if(otaPrecentageComplete >= 0) otaProgress();
|
||||
}
|
@ -4,6 +4,7 @@
|
||||
#include "ArduinoJson.h"
|
||||
|
||||
void otaSetup(JsonObject settings);
|
||||
void otaLoop(bool wifiIsConnected);
|
||||
void otaLoop(void);
|
||||
void otaEverySecond(void);
|
||||
|
||||
#endif
|
27
src/main.cpp
27
src/main.cpp
@ -88,15 +88,15 @@ void setup()
|
||||
wifiSetup(settings[F("wifi")]);
|
||||
|
||||
#if HASP_USE_MQTT
|
||||
mqttSetup(settings[F("mqtt")]);
|
||||
// mqttSetup(settings[F("mqtt")]);
|
||||
#endif
|
||||
|
||||
#if HASP_USE_TELNET
|
||||
telnetSetup(settings[F("telnet")]);
|
||||
// telnetSetup(settings[F("telnet")]);
|
||||
#endif
|
||||
|
||||
#if HASP_USE_MDNS
|
||||
mdnsSetup(settings[F("mdns")]);
|
||||
// mdnsSetup(settings[F("mdns")]);
|
||||
#endif
|
||||
|
||||
#if HASP_USE_HTTP
|
||||
@ -134,30 +134,39 @@ void loop()
|
||||
/* Network Services Loops */
|
||||
#if HASP_USE_WIFI
|
||||
isConnected = wifiLoop();
|
||||
|
||||
#if HASP_USE_MQTT
|
||||
mqttLoop(isConnected);
|
||||
#endif
|
||||
|
||||
if(isConnected) {
|
||||
#if HASP_USE_HTTP
|
||||
httpLoop(isConnected);
|
||||
httpLoop();
|
||||
#endif
|
||||
|
||||
#if HASP_USE_TELNET
|
||||
telnetLoop(isConnected);
|
||||
telnetLoop();
|
||||
#endif
|
||||
|
||||
#if HASP_USE_MDNS
|
||||
mdnsLoop(isConnected);
|
||||
mdnsLoop();
|
||||
#endif
|
||||
|
||||
#if HASP_USE_BUTTON
|
||||
buttonLoop();
|
||||
buttonLoop();
|
||||
#endif
|
||||
}
|
||||
|
||||
otaLoop(isConnected);
|
||||
otaLoop();
|
||||
debugLoop();
|
||||
#endif
|
||||
|
||||
static unsigned long mainLastLoopTime = 0;
|
||||
|
||||
// Every Secons Loop
|
||||
if(millis() - mainLastLoopTime >= 1000) {
|
||||
mainLastLoopTime += 1000;
|
||||
otaEverySecond();
|
||||
}
|
||||
|
||||
// delay(1);
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user