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.

83 lines
2.1 KiB

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