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