ota.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. }
  32. void loopOTA(){
  33. if (loop_counter == 10) {
  34. loop_counter = 0;
  35. server.handleClient();
  36. Red_Led_State = !Red_Led_State;
  37. digitalWrite(Red_Led, Red_Led_State);
  38. delay(10);
  39. }
  40. if (loop_counter == 5) {
  41. ArduinoOTA.handle();
  42. delay(10);
  43. }
  44. loop_counter += 1;
  45. if (Refresh) {
  46. Refresh = false;
  47. ///Serial.println("Refreshing...");
  48. //Serial.printf("FreeMem:%d %d:%d:%d %d.%d.%d \n",ESP.getFreeHeap() , DateTime.hour,DateTime.minute, DateTime.second, DateTime.year, DateTime.month, DateTime.day);
  49. }
  50. }