-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcodeOTA.cpp
36 lines (33 loc) · 1.03 KB
/
codeOTA.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include "codeOTA.h"
CodeOTA::CodeOTA(
const char* otaHostName,
const char* otaPassword
) {
_otaHostName = otaHostName;
_otaPassword = otaPassword;
}
void CodeOTA::setup() {
ArduinoOTA.setHostname(_otaHostName);
ArduinoOTA.setPassword(_otaPassword);
ArduinoOTA.onStart([]() {
Serial.println("Start");
});
ArduinoOTA.onEnd([]() {
Serial.println("\nEnd");
});
ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
Serial.printf("Progress: %u%%\r", (progress / (total / 100)));
});
ArduinoOTA.onError([](ota_error_t error) {
Serial.printf("Error[%u]: ", error);
if (error == OTA_AUTH_ERROR) Serial.println("Auth Failed");
else if (error == OTA_BEGIN_ERROR) Serial.println("Begin Failed");
else if (error == OTA_CONNECT_ERROR) Serial.println("Connect Failed");
else if (error == OTA_RECEIVE_ERROR) Serial.println("Receive Failed");
else if (error == OTA_END_ERROR) Serial.println("End Failed");
});
ArduinoOTA.begin();
}
void CodeOTA::loop() {
ArduinoOTA.handle();
}