OTAUpdater.h 587 B

123456789101112131415161718192021222324252627
  1. #ifndef OTA_UPDATER_H
  2. #define OTA_UPDATER_H
  3. #include <WiFi.h>
  4. #include <HTTPClient.h>
  5. #include <Update.h>
  6. // 使用 extern 声明全局变量 deviceID 和 serverAddress
  7. extern String deviceID;
  8. extern String serverAddress;
  9. void setupWiFiConfig();
  10. bool connectWiFiWithTimeout(uint32_t timeoutMs);
  11. class OTAUpdater {
  12. public:
  13. OTAUpdater(uint16_t port, const String& currentVersion); // 移除 serverUrl 参数
  14. void checkForUpdates();
  15. private:
  16. uint16_t _port; // 端口号
  17. String _currentVersion; // 当前固件版本
  18. bool downloadAndUpdateFirmware();
  19. };
  20. #endif