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.

84 lines
2.1 KiB

  1. /*
  2. ESPurna
  3. NOFUSS MODULE
  4. Copyright (C) 2016-2017 by Xose Pérez <xose dot perez at gmail dot com>
  5. */
  6. #if ENABLE_NOFUSS
  7. #include "NoFUSSClient.h"
  8. // -----------------------------------------------------------------------------
  9. // NOFUSS
  10. // -----------------------------------------------------------------------------
  11. void nofussSetup() {
  12. NoFUSSClient.setServer(getSetting("nofussServer", NOFUSS_SERVER));
  13. NoFUSSClient.setDevice(DEVICE);
  14. NoFUSSClient.setVersion(APP_VERSION);
  15. NoFUSSClient.onMessage([](nofuss_t code) {
  16. if (code == NOFUSS_START) {
  17. DEBUG_MSG("[NoFUSS] Start\n");
  18. }
  19. if (code == NOFUSS_UPTODATE) {
  20. DEBUG_MSG("[NoFUSS] Already in the last version\n");
  21. }
  22. if (code == NOFUSS_PARSE_ERROR) {
  23. DEBUG_MSG("[NoFUSS] Error parsing server response\n");
  24. }
  25. if (code == NOFUSS_UPDATING) {
  26. DEBUG_MSG("[NoFUSS] Updating");
  27. DEBUG_MSG(" New version: %s\n", (char *) NoFUSSClient.getNewVersion().c_str());
  28. DEBUG_MSG(" Firmware: %s\n", (char *) NoFUSSClient.getNewFirmware().c_str());
  29. DEBUG_MSG(" File System: %s", (char *) NoFUSSClient.getNewFileSystem().c_str());
  30. }
  31. if (code == NOFUSS_FILESYSTEM_UPDATE_ERROR) {
  32. DEBUG_MSG("[NoFUSS] File System Update Error: %s\n", (char *) NoFUSSClient.getErrorString().c_str());
  33. }
  34. if (code == NOFUSS_FILESYSTEM_UPDATED) {
  35. DEBUG_MSG("[NoFUSS] File System Updated\n");
  36. }
  37. if (code == NOFUSS_FIRMWARE_UPDATE_ERROR) {
  38. DEBUG_MSG("[NoFUSS] Firmware Update Error: %s\n", (char *) NoFUSSClient.getErrorString().c_str());
  39. }
  40. if (code == NOFUSS_FIRMWARE_UPDATED) {
  41. DEBUG_MSG("[NoFUSS] Firmware Updated\n");
  42. }
  43. if (code == NOFUSS_RESET) {
  44. DEBUG_MSG("[NoFUSS] Resetting board\n");
  45. }
  46. if (code == NOFUSS_END) {
  47. DEBUG_MSG("[NoFUSS] End\n");
  48. }
  49. });
  50. }
  51. void nofussLoop() {
  52. static unsigned long last_check = 0;
  53. if (!wifiConnected()) return;
  54. unsigned long interval = getSetting("nofussInterval", NOFUSS_INTERVAL).toInt();
  55. if ((last_check > 0) && ((millis() - last_check) < interval)) return;
  56. last_check = millis();
  57. NoFUSSClient.handle();
  58. }
  59. #endif