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.

65 lines
1.2 KiB

  1. #ifndef _AUTO_OTA_h
  2. #define _AUTO_OTA_h
  3. #include <functional>
  4. #include <ArduinoJson.h>
  5. #include <ESP8266httpUpdate.h>
  6. typedef enum {
  7. AUTO_OTA_START,
  8. AUTO_OTA_UPTODATE,
  9. AUTO_OTA_UPDATING,
  10. AUTO_OTA_FILESYSTEM_UPDATED,
  11. AUTO_OTA_FIRMWARE_UPDATED,
  12. AUTO_OTA_RESET,
  13. AUTO_OTA_END,
  14. AUTO_OTA_NO_RESPONSE_ERROR,
  15. AUTO_OTA_PARSE_ERROR,
  16. AUTO_OTA_FILESYSTEM_UPDATE_ERROR,
  17. AUTO_OTA_FIRMWARE_UPDATE_ERROR
  18. } auto_ota_t;
  19. class AutoOTAClass {
  20. public:
  21. typedef std::function<void(auto_ota_t)> TMessageFunction;
  22. void setServer(String server);
  23. void setModel(String model);
  24. void setVersion(String version);
  25. String getNewVersion();
  26. String getNewFirmware();
  27. String getNewFileSystem();
  28. int getErrorNumber();
  29. String getErrorString();
  30. void onMessage(TMessageFunction fn);
  31. void handle();
  32. private:
  33. String _server;
  34. String _model;
  35. String _version;
  36. String _newVersion;
  37. String _newFirmware;
  38. String _newFileSystem;
  39. int _errorNumber;
  40. String _errorString;
  41. TMessageFunction _callback;
  42. String _getPayload();
  43. bool _checkUpdates();
  44. void _doUpdate();
  45. };
  46. extern AutoOTAClass AutoOTA;
  47. #endif /* _AUTO_OTA_h */