-
Notifications
You must be signed in to change notification settings - Fork 0
/
Bricks.OtaSkill.cpp
51 lines (46 loc) · 1.26 KB
/
Bricks.OtaSkill.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
#include "Bricks.OtaSkill.h"
namespace Bricks {
OtaSkill::OtaSkill() : Skill("setOta") {
}
void OtaSkill::loop() {
ArduinoOTA.handle();
}
void OtaSkill::callback(BRICKS_CALLBACK_SIGNATURE) {
initOta();
startAP();
strcpy(response, "Connect to 'Brick - OTA'");
}
void OtaSkill::initOta() {
ArduinoOTA.onStart([]() {
Log.notice("AOTA: Starting OTA" CR);
});
ArduinoOTA.onEnd([]() {
Log.notice("AOTA: Done" CR);
});
ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
Log.trace("Progress: %u%%\r", (progress / (total / 100)));
});
ArduinoOTA.onError([](ota_error_t error) {
if (error == OTA_AUTH_ERROR) {
Log.error("AOTA: Auth Failed");
}
else if (error == OTA_BEGIN_ERROR) {
Log.error("AOTA: Begin Failed");
}
else if (error == OTA_CONNECT_ERROR) {
Log.error("AOTA: Connect Failed");
}
else if (error == OTA_RECEIVE_ERROR) {
Log.error("AOTA: Receive Failed");
}
else if (error == OTA_END_ERROR) {
Log.error("AOTA: End Failed");
}
});
ArduinoOTA.begin();
}
void OtaSkill::startAP() {
WiFi.mode(WIFI_AP);
WiFi.softAP("Brick - OTA", NULL, BRICKS_WIFI_CHANNEL, false, 1);
}
}