|
@@ -1,23 +1,31 @@
|
|
|
+Ticker tkOTA; // periodic check if OTA available
|
|
|
+int OTA_check_ms = 100;
|
|
|
+
|
|
|
+void loopOTA(){
|
|
|
+
|
|
|
+ ArduinoOTA.handle();
|
|
|
+ //Serial.println("OTA check");
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
void setupOTA(){
|
|
|
ArduinoOTA.onStart([]() {
|
|
|
- Serial.println("Start");
|
|
|
- digitalWrite(Red_Led, HIGH);
|
|
|
- digitalWrite(Blue_Led, LOW);
|
|
|
- delay(1000);
|
|
|
- digitalWrite(Blue_Led, HIGH);
|
|
|
- delay(500);
|
|
|
+ Serial.println("Starting firmware update");
|
|
|
+ redLedState(-1,100); // fast red blink
|
|
|
});
|
|
|
ArduinoOTA.onEnd([]() {
|
|
|
- Serial.println("End");
|
|
|
- digitalWrite(Blue_Led, HIGH);
|
|
|
- delay(1000);
|
|
|
+ Serial.println("update done !");
|
|
|
+ redLedState(0, 500);
|
|
|
+ blueLedState(-1, 100); // 5 fast blue blink on end
|
|
|
+ delay(500);
|
|
|
+ blueLedState(0,100);
|
|
|
//ledBlink(Blue_Led, 3, 100);
|
|
|
|
|
|
});
|
|
|
ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
|
|
|
Serial.printf("Progress: %u%%\n", (progress / (total / 100)));
|
|
|
- digitalWrite(Blue_Led, Blue_Led_State);
|
|
|
- Blue_Led_State = !Blue_Led_State;
|
|
|
+ blueLedState(-1,500); //slow blue blink during progress
|
|
|
|
|
|
});
|
|
|
ArduinoOTA.onError([](ota_error_t error) {
|
|
@@ -27,19 +35,13 @@ void setupOTA(){
|
|
|
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");
|
|
|
- digitalWrite(Blue_Led, HIGH);
|
|
|
+ redLedState(-1, 250);
|
|
|
+ blueLedState(-1,250);
|
|
|
});
|
|
|
ArduinoOTA.begin();
|
|
|
Serial.println("OTA started");
|
|
|
+ tkOTA.attach_ms(OTA_check_ms, loopOTA);
|
|
|
}
|
|
|
|
|
|
-void loopOTA(){
|
|
|
-
|
|
|
- if (loop_counter == 5) {
|
|
|
- ArduinoOTA.handle();
|
|
|
- delay(10);
|
|
|
- }
|
|
|
-
|
|
|
|
|
|
-}
|
|
|
|