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.

51 lines
1.3 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 otaSetup() {
  11. ArduinoOTA.setPort(OTA_PORT);
  12. ArduinoOTA.setHostname(getSetting("hostname", HOSTNAME).c_str());
  13. ArduinoOTA.setPassword((const char *) OTA_PASS);
  14. ArduinoOTA.onStart([]() {
  15. DEBUG_MSG("[OTA] Start\n");
  16. });
  17. ArduinoOTA.onEnd([]() {
  18. DEBUG_MSG("\n[OTA] End\n");
  19. });
  20. ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
  21. DEBUG_MSG("[OTA] Progress: %u%%\r", (progress / (total / 100)));
  22. });
  23. ArduinoOTA.onError([](ota_error_t error) {
  24. #if DEBUG_PORT
  25. DEBUG_MSG("\n[OTA] Error[%u]: ", error);
  26. if (error == OTA_AUTH_ERROR) DEBUG_MSG("Auth Failed\n");
  27. else if (error == OTA_BEGIN_ERROR) DEBUG_MSG("Begin Failed\n");
  28. else if (error == OTA_CONNECT_ERROR) DEBUG_MSG("Connect Failed\n");
  29. else if (error == OTA_RECEIVE_ERROR) DEBUG_MSG("Receive Failed\n");
  30. else if (error == OTA_END_ERROR) DEBUG_MSG("End Failed\n");
  31. #endif
  32. });
  33. ArduinoOTA.begin();
  34. }
  35. void otaLoop() {
  36. ArduinoOTA.handle();
  37. }