ESP8266 Treppenlichtsteuerung mit OTA zum Firmware Upload
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ota.h 1.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #ifndef __OTA_H
  2. #define __OTA_H
  3. void ota_setup() {
  4. ArduinoOTA.setPort(8266);
  5. ArduinoOTA.setHostname("ESP_Treppenlicht");
  6. ArduinoOTA.setPassword("admin");
  7. // Password can be set with it's md5 value as well
  8. // MD5(admin) = 21232f297a57a5a743894a0e4a801fc3
  9. // ArduinoOTA.setPasswordHash("21232f297a57a5a743894a0e4a801fc3");
  10. ArduinoOTA.onStart([]() {
  11. String type;
  12. if (ArduinoOTA.getCommand() == U_FLASH) {
  13. type = "sketch";
  14. } else { // U_FS
  15. type = "filesystem";
  16. }
  17. // NOTE: if updating FS this would be the place to unmount FS using FS.end()
  18. Serial.println("Start updating " + type);
  19. });
  20. ArduinoOTA.onEnd([]() {
  21. Serial.println("\nEnd");
  22. });
  23. ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
  24. Serial.printf("Progress: %u%%\r", (progress / (total / 100)));
  25. });
  26. ArduinoOTA.onError([](ota_error_t error) {
  27. Serial.printf("Error[%u]: ", error);
  28. if (error == OTA_AUTH_ERROR) {
  29. Serial.println("Auth Failed");
  30. } else if (error == OTA_BEGIN_ERROR) {
  31. Serial.println("Begin Failed");
  32. } else if (error == OTA_CONNECT_ERROR) {
  33. Serial.println("Connect Failed");
  34. } else if (error == OTA_RECEIVE_ERROR) {
  35. Serial.println("Receive Failed");
  36. } else if (error == OTA_END_ERROR) {
  37. Serial.println("End Failed");
  38. }
  39. });
  40. ArduinoOTA.begin();
  41. }
  42. #endif // __OTA_H