1616#include < LittleFS.h>
1717#include < OneButton.h>
1818#include " statusled.h"
19- #include < ArduinoOTA.h>
2019#include < AsyncTCP.h>
2120#include < asyncbufferedtcplogger.h>
2221#include " influxdb.h"
22+ #include < arduinoota-manager.h>
23+ #include < ArduinoOTA.h>
2324
2425Scheduler scheduler;
2526
@@ -39,8 +40,6 @@ APB::WebServer webServer(scheduler);
3940using namespace std ::placeholders;
4041using namespace GuLinux ;
4142
42- void setupArduinoOTA ();
43-
4443void setup () {
4544 Serial.begin (115200 );
4645 #ifdef WAIT_FOR_SERIAL
@@ -74,7 +73,7 @@ void setup() {
7473 std::for_each (APB::Heaters::Instance.begin (), APB::Heaters::Instance.end (), [i=0 ](APB::Heater &heater) mutable { heater.setup (i++, scheduler); });
7574
7675 webServer.setup ();
77- setupArduinoOTA ( );
76+ ArduinoOTAManager::Instance. setup (&LittleFS );
7877 APB::History::Instance.setup (scheduler);
7978
8079#ifdef ONEBUTTON_USER_BUTTON_1
@@ -94,46 +93,5 @@ void loop() {
9493#ifdef ONEBUTTON_USER_BUTTON_1
9594 userButton.tick ();
9695#endif
97- ArduinoOTA. handle ();
96+ ArduinoOTAManager::Instance. loop ();
9897}
99-
100- void setupArduinoOTA () {
101- ArduinoOTA
102- .onStart ([]() {
103- String type;
104- if (ArduinoOTA.getCommand () == U_FLASH) {
105- type = " sketch" ;
106- } else { // U_SPIFFS
107- type = " filesystem" ;
108- }
109-
110- // NOTE: if updating SPIFFS this would be the place to unmount SPIFFS using SPIFFS.end()
111- Log.infoln (" Start updating %s" , type.c_str ());
112- LittleFS.end ();
113- })
114- .onEnd ([]() {
115- Log.infoln (" \n End" );
116- })
117- .onProgress ([](unsigned int progress, unsigned int total) {
118- Log.infoln (" Progress: %u%%\r " , (progress / (total / 100 )));
119- })
120- .onError ([](ota_error_t error) {
121- String errorMessage;
122- if (error == OTA_AUTH_ERROR) {
123- errorMessage = " Auth Failed" ;
124- } else if (error == OTA_BEGIN_ERROR) {
125- errorMessage = " Begin Failed" ;
126- } else if (error == OTA_CONNECT_ERROR) {
127- errorMessage = " Connect Failed" ;
128- } else if (error == OTA_RECEIVE_ERROR) {
129- errorMessage = " Receive Failed" ;
130- } else if (error == OTA_END_ERROR) {
131- errorMessage = " End Failed" ;
132- } else {
133- errorMessage = " Unknown error" ;
134- }
135- Log.errorln (" Error[%u]: %s" , error, errorMessage.c_str ());
136- });
137-
138- ArduinoOTA.begin ();
139- }
0 commit comments