forked from dirkx/makerspaceleiden-payment-node
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ota.cpp
53 lines (48 loc) · 1.34 KB
/
ota.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <WiFi.h>
#include <HTTPClient.h>
#include <WiFiUdp.h>
#include <ArduinoOTA.h>
#include <ESPmDNS.h>
#include "global.h"
#include "display.h"
#include "rest.h"
#include "ota.h"
void setupOTA() {
ArduinoOTA.setHostname(terminalName);
#ifdef OTA_HASH
ArduinoOTA.setPasswordHash(OTA_HASH);
#else
#ifdef OTA_PASSWORD
ArduinoOTA.setPassword(OTA_PASSWORD);
#endif
#endif
ArduinoOTA
.onStart([]() {
led_loop(BOOT);
updateDisplay_startProgressBar("firmware update");
})
.onEnd([]() {
// wipe the keys - to prevent some cleversod from uploading something to
// extract them keys. We ignore the serial angle - as that needs HW
// protection and an ESP32-S2.
wipekeys();
})
.onProgress([](unsigned int progress, unsigned int total) {
updateDisplay_progressBar(1.0 * progress / total);
})
.onError([](ota_error_t error) {
const char * str;
if (error == OTA_AUTH_ERROR) str = "Auth Failed";
else if (error == OTA_BEGIN_ERROR) str = "Begin Failed";
else if (error == OTA_CONNECT_ERROR) str = "Connect Failed";
else if (error == OTA_RECEIVE_ERROR) str = "Receive Failed";
else if (error == OTA_END_ERROR) str = "End Failed";
else str = "Uknown error";
displayForceShowErrorModal("OTA abort", str);
delay(2500);
});
ArduinoOTA.begin();
};
void ota_loop() {
ArduinoOTA.handle();
}