12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- Ticker tkOTA;
- int OTA_check_ms = 100;
- bool flag_OTA = false;
- void OTA_Flag(){
- flag_OTA = true ;
- }
- void checkOTA(){
-
- if (flag_OTA){
- flag_OTA = false ;
- ArduinoOTA.handle();
-
- }
-
- }
- void detachOTA(){
- tkOTA.detach();
- }
- void setupOTA(){
- ArduinoOTA.onStart([]() {
- Serial.println("Starting firmware update");
- redLedState(-1,100);
- });
- ArduinoOTA.onEnd([]() {
- Serial.println("update done !");
- redLedState(0, 500);
- blueLedState(-1, 100);
- delay(500);
- blueLedState(0,100);
-
- });
- ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
- Serial.printf("Progress: %u%%\n", (progress / (total / 100)));
- blueLedState(-1,500);
- });
- 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");
- redLedState(-1, 250);
- blueLedState(-1,250);
- });
- ArduinoOTA.begin();
- Serial.println("OTA started");
- tkOTA.attach_ms(OTA_check_ms, OTA_Flag);
- }
|