ota.h 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. void setupOTA(){
  2. ArduinoOTA.onStart([]() {
  3. Serial.println("Start");
  4. digitalWrite(Red_Led, HIGH);
  5. digitalWrite(Blue_Led, LOW);
  6. delay(1000);
  7. digitalWrite(Blue_Led, HIGH);
  8. delay(500);
  9. });
  10. ArduinoOTA.onEnd([]() {
  11. Serial.println("End");
  12. digitalWrite(Blue_Led, HIGH);
  13. delay(1000);
  14. //ledBlink(Blue_Led, 3, 100);
  15. });
  16. ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
  17. Serial.printf("Progress: %u%%\n", (progress / (total / 100)));
  18. digitalWrite(Blue_Led, Blue_Led_State);
  19. Blue_Led_State = !Blue_Led_State;
  20. });
  21. ArduinoOTA.onError([](ota_error_t error) {
  22. Serial.printf("Error[%u]: ", error);
  23. if (error == OTA_AUTH_ERROR) Serial.println("Auth Failed");
  24. else if (error == OTA_BEGIN_ERROR) Serial.println("Begin Failed");
  25. else if (error == OTA_CONNECT_ERROR) Serial.println("Connect Failed");
  26. else if (error == OTA_RECEIVE_ERROR) Serial.println("Receive Failed");
  27. else if (error == OTA_END_ERROR) Serial.println("End Failed");
  28. digitalWrite(Blue_Led, HIGH);
  29. });
  30. ArduinoOTA.begin();
  31. Serial.println("OTA started");
  32. }
  33. void loopOTA(){
  34. if (loop_counter == 5) {
  35. ArduinoOTA.handle();
  36. delay(10);
  37. }
  38. }