Fork of the espurna firmware for `mhsw` switches
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.

55 lines
1.4 KiB

8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
  1. /*
  2. ESPurna
  3. OTA MODULE
  4. Copyright (C) 2016 by Xose Pérez <xose dot perez at gmail dot com>
  5. */
  6. #include "ArduinoOTA.h"
  7. // -----------------------------------------------------------------------------
  8. // OTA
  9. // -----------------------------------------------------------------------------
  10. void otaConfigure() {
  11. ArduinoOTA.setPort(OTA_PORT);
  12. ArduinoOTA.setHostname(getSetting("hostname", HOSTNAME).c_str());
  13. ArduinoOTA.setPassword(getSetting("adminPass", ADMIN_PASS).c_str());
  14. }
  15. void otaSetup() {
  16. otaConfigure();
  17. ArduinoOTA.onStart([]() {
  18. DEBUG_MSG("[OTA] Start\n");
  19. });
  20. ArduinoOTA.onEnd([]() {
  21. DEBUG_MSG("\n[OTA] End\n");
  22. });
  23. ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
  24. DEBUG_MSG("[OTA] Progress: %u%%\r", (progress / (total / 100)));
  25. });
  26. ArduinoOTA.onError([](ota_error_t error) {
  27. #if DEBUG_PORT
  28. DEBUG_MSG("\n[OTA] Error[%u]: ", error);
  29. if (error == OTA_AUTH_ERROR) DEBUG_MSG("Auth Failed\n");
  30. else if (error == OTA_BEGIN_ERROR) DEBUG_MSG("Begin Failed\n");
  31. else if (error == OTA_CONNECT_ERROR) DEBUG_MSG("Connect Failed\n");
  32. else if (error == OTA_RECEIVE_ERROR) DEBUG_MSG("Receive Failed\n");
  33. else if (error == OTA_END_ERROR) DEBUG_MSG("End Failed\n");
  34. #endif
  35. });
  36. ArduinoOTA.begin();
  37. }
  38. void otaLoop() {
  39. ArduinoOTA.handle();
  40. }