ota.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. Ticker tkOTA; // periodic check if OTA available
  2. int OTA_check_ms = 100;
  3. void loopOTA(){
  4. ArduinoOTA.handle();
  5. //Serial.println("OTA check");
  6. }
  7. void setupOTA(){
  8. ArduinoOTA.onStart([]() {
  9. Serial.println("Starting firmware update");
  10. redLedState(-1,100); // fast red blink
  11. });
  12. ArduinoOTA.onEnd([]() {
  13. Serial.println("update done !");
  14. redLedState(0, 500);
  15. blueLedState(-1, 100); // 5 fast blue blink on end
  16. delay(500);
  17. blueLedState(0,100);
  18. //ledBlink(Blue_Led, 3, 100);
  19. });
  20. ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
  21. Serial.printf("Progress: %u%%\n", (progress / (total / 100)));
  22. blueLedState(-1,500); //slow blue blink during progress
  23. });
  24. ArduinoOTA.onError([](ota_error_t error) {
  25. Serial.printf("Error[%u]: ", error);
  26. if (error == OTA_AUTH_ERROR) Serial.println("Auth Failed");
  27. else if (error == OTA_BEGIN_ERROR) Serial.println("Begin Failed");
  28. else if (error == OTA_CONNECT_ERROR) Serial.println("Connect Failed");
  29. else if (error == OTA_RECEIVE_ERROR) Serial.println("Receive Failed");
  30. else if (error == OTA_END_ERROR) Serial.println("End Failed");
  31. redLedState(-1, 250);
  32. blueLedState(-1,250);
  33. });
  34. ArduinoOTA.begin();
  35. Serial.println("OTA started");
  36. tkOTA.attach_ms(OTA_check_ms, loopOTA);
  37. }