8#include "ustd_platform.h"
13#include "filesystem.h"
15#include <ArduinoOTA.h>
16#include <Arduino_JSON.h>
65 bool bCheckOTA =
false;
66 bool bOTAUpdateActive =
false;
76 void begin(Scheduler *_pSched) {
87 tID = pSched->add([
this]() { this->loop(); },
"ota", 25000L);
90 pSched->subscribe(tID,
"#", [
this](String topic, String msg, String originator) {
91 this->subsMsg(topic, msg, originator);
94 pSched->publish(
"net/network/get");
104 void subsMsg(String topic, String msg, String originator) {
105 JSONVar mqttJsonMsg = JSON.parse(msg);
107 if (JSON.typeof(mqttJsonMsg) ==
"undefined") {
111 if (topic ==
"net/network") {
112 String state = (
const char *)mqttJsonMsg[
"state"];
113 if (state ==
"connected") {
128#if defined(__ESP32__)
129 ArduinoOTA.setHostname(WiFi.getHostname());
131 ArduinoOTA.setHostname(WiFi.hostname().c_str());
141 ArduinoOTA.onStart([&]() {
143 if (ArduinoOTA.getCommand() == U_FLASH)
148 DBG(
"Start updating " + type);
149 bOTAUpdateActive =
true;
150 pSched->singleTaskMode(tID);
153 ArduinoOTA.onEnd([&]() {
154 DBG(
"\nEnd of update");
155 pSched->singleTaskMode(-1);
156 bOTAUpdateActive =
false;
158 ArduinoOTA.onProgress([](
unsigned int progress,
unsigned int total) {
159 DBGF(
"Progress: %u%%\r", (progress / (total / 100)));
161 ArduinoOTA.onError([&](ota_error_t error) {
163 Serial.printf(
"Error[%u]: ", error);
164 if (error == OTA_AUTH_ERROR)
165 Serial.println(
"Auth Failed");
166 else if (error == OTA_BEGIN_ERROR)
167 Serial.println(
"Begin Failed");
168 else if (error == OTA_CONNECT_ERROR)
169 Serial.println(
"Connect Failed");
170 else if (error == OTA_RECEIVE_ERROR)
171 Serial.println(
"Receive Failed");
172 else if (error == OTA_END_ERROR)
173 Serial.println(
"End Failed");
munet OTA Class
Definition: ota.h:57
void begin(Scheduler *_pSched)
Definition: ota.h:76
Ota()
Definition: ota.h:69
The muwerk namespace.
Definition: mqtt.h:21