OTAUpdater.h 641 B

12345678910111213141516171819202122232425262728
  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. extern uint16_t otaPort; // 新增 OTA 端口号
  10. void setupWiFiConfig();
  11. bool connectWiFiWithTimeout(uint32_t timeoutMs);
  12. class OTAUpdater {
  13. public:
  14. OTAUpdater(uint16_t port, const String& currentVersion); // 移除 serverUrl 参数
  15. void checkForUpdates();
  16. private:
  17. uint16_t _port; // 端口号
  18. String _currentVersion; // 当前固件版本
  19. bool downloadAndUpdateFirmware();
  20. };
  21. #endif