-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOTA.ino
38 lines (28 loc) · 1.09 KB
/
OTA.ino
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
37
38
void ota_init(const char* name) {
// Port defaults to 8266
// ArduinoOTA.setPort(8266);
// Hostname defaults to esp8266-[ChipID]
// ArduinoOTA.setHostname("myesp8266");
ArduinoOTA.setHostname(name);
// No authentication by default
// ArduinoOTA.setPassword((const char *)"123");
ArduinoOTA.onStart([]() {
Serial.println("OTA Start");
});
ArduinoOTA.onEnd([]() {
Serial.println("\nOTA End");
});
ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
Serial.printf("OTA Progress: %u%%\r", (progress / (total / 100)));
});
ArduinoOTA.onError([](ota_error_t error) {
Serial.printf("OTA Error[%u]: ", error);
if (error == OTA_AUTH_ERROR) Serial.println("OTA Auth Failed");
else if (error == OTA_BEGIN_ERROR) Serial.println("OTA Begin Failed");
else if (error == OTA_CONNECT_ERROR) Serial.println("OTA Connect Failed");
else if (error == OTA_RECEIVE_ERROR) Serial.println("OTA Receive Failed");
else if (error == OTA_END_ERROR) Serial.println("OTA End Failed");
});
ArduinoOTA.begin();
Serial.println("OTA Ready");
}