From 81a4026562ba4fdd03214a1897af6f19666a6bc2 Mon Sep 17 00:00:00 2001 From: Rune Harlyk Date: Sat, 6 May 2023 02:27:06 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=93=A1=20Adds=20standard=20OAT?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/main.cpp b/src/main.cpp index e95c63a..4f380e4 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include @@ -105,6 +106,23 @@ bool setupMPU(){ return 1; } +void setupOAT(){ + ArduinoOTA.onStart([]() { events.send("Update Start", "ota"); }); + ArduinoOTA.onEnd([]() { events.send("Update End", "ota"); }); + ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) { + char p[32]; + sprintf(p, "Progress: %u%%\n", (progress/(total/100))); + events.send(p, "ota"); + }); + ArduinoOTA.onError([](ota_error_t error) { + if(error == OTA_AUTH_ERROR) events.send("Auth Failed", "ota"); + else if(error == OTA_BEGIN_ERROR) events.send("Begin Failed", "ota"); + else if(error == OTA_CONNECT_ERROR) events.send("Connect Failed", "ota"); + else if(error == OTA_RECEIVE_ERROR) events.send("Recieve Failed", "ota"); + else if(error == OTA_END_ERROR) events.send("End Failed", "ota"); + }); + ArduinoOTA.setHostname(HOSTNAME); + ArduinoOTA.begin(); } void setup(){ @@ -124,6 +142,7 @@ void setup(){ } void loop(){ + ArduinoOTA.handle(); if(USE_CAPTIVE_PORTAL) dnsServer.processNextRequest(); ws.cleanupClients();