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

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