/* esp32 firmware OTA Date: December 2018 Author: Chris Joyce Purpose: Perform an OTA update from a bin located on a webserver (HTTP Only) Modifications Dec 2019: RLJ Added usage of asyncHTTPrequest to avoid hang issues with flaky internet connections during update poll However using AsyncTCP for the actual binary update causes other issues in the callback realm, so persisting with the original synchronous update method which blocks all user mode code. */ #ifndef esp32fota_h #define esp32fota_h //#include #include #include "../../asyncHTTPrequest/src/asyncHTTPrequest.h" #include "freertos/queue.h" struct sFOTAqueue{ uint8_t len; uint8_t data[255]; }; class esp32FOTA { public: esp32FOTA(String firwmareType, int firwmareVersion, bool isBeta); void execOTA(); bool execHTTPcheck(); bool useDeviceID; void onProgress( std::function func ); void onComplete( std::function func ); void onSuccess( std::function func ); void onFail( std::function func ); int getNewVersion() { return _newVersion; }; void setCheckURL(const char* host); void setupAsync(const char* host); void execAsyncHTTPcheck(); bool decodeResponse(String payload); bool decodeResponse(char* resp); void process(); void queueDLdata(asyncHTTPrequest* request); private: String getHeaderValue(String header, String headerName); String getDeviceID(); String _firwmareType; int _firwmareVersion; int _newVersion; bool _bIsBeta; String _checkURL; String _host; String _bin; int _port; std::function _onComplete; std::function _onSuccess; std::function _onFail; asyncHTTPrequest _versionTest; QueueHandle_t _queue; String _pollResponse; }; #endif