Skip to content

Commit ffbc90a

Browse files
committed
Extract ArduinoOTA setup
1 parent 5509b4b commit ffbc90a

2 files changed

Lines changed: 5 additions & 46 deletions

File tree

platformio.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ lib_deps =
2121
https://github.com/GuLinux/AsyncBufferedTcpLogger#v0.0.2
2222
https://github.com/GuLinux/AsyncWebserverUtils#v0.0.2
2323
https://github.com/GuLinux/WiFiManager.git#v0.0.1
24+
https://github.com/GuLinux/ArduinoOTA-Manager.git#v0.0.1
2425
ayushsharma82/ElegantOTA @ 3.1.1
2526
bblanchon/ArduinoJson@^7.2.0
2627
adafruit/Adafruit Unified Sensor@^1.1.14

src/main.cpp

Lines changed: 4 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@
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

2425
Scheduler scheduler;
2526

@@ -39,8 +40,6 @@ APB::WebServer webServer(scheduler);
3940
using namespace std::placeholders;
4041
using namespace GuLinux;
4142

42-
void setupArduinoOTA();
43-
4443
void 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("\nEnd");
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

Comments
 (0)