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