2019-07-25 11:27:57 +00:00
|
|
|
/*
|
|
|
|
esp32 firmware OTA
|
|
|
|
Date: December 2018
|
|
|
|
Author: Chris Joyce <https://chrisjoyce911/esp32FOTA>
|
|
|
|
Purpose: Perform an OTA update from a bin located on a webserver (HTTP Only)
|
2020-01-04 07:13:40 +00:00
|
|
|
|
|
|
|
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.
|
2019-07-25 11:27:57 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef esp32fota_h
|
|
|
|
#define esp32fota_h
|
|
|
|
|
|
|
|
//#include <Arduino.h>
|
|
|
|
#include <functional>
|
2019-12-15 06:58:11 +00:00
|
|
|
#include "../../asyncHTTPrequest/src/asyncHTTPrequest.h"
|
2020-03-25 09:28:12 +00:00
|
|
|
#include "freertos/queue.h"
|
|
|
|
|
|
|
|
struct sFOTAqueue{
|
|
|
|
uint8_t len;
|
|
|
|
uint8_t data[255];
|
|
|
|
};
|
2019-07-25 11:27:57 +00:00
|
|
|
|
|
|
|
class esp32FOTA
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
esp32FOTA(String firwmareType, int firwmareVersion);
|
|
|
|
void execOTA();
|
|
|
|
bool execHTTPcheck();
|
|
|
|
bool useDeviceID;
|
2019-08-03 02:42:49 +00:00
|
|
|
void onProgress( std::function<void(size_t, size_t)> func );
|
2019-07-25 11:27:57 +00:00
|
|
|
void onComplete( std::function<bool(int)> func );
|
|
|
|
void onSuccess( std::function<void()> func );
|
|
|
|
void onFail( std::function<void()> func );
|
2019-08-03 02:42:49 +00:00
|
|
|
int getNewVersion() { return _newVersion; };
|
2019-12-15 06:58:11 +00:00
|
|
|
|
2020-01-04 07:13:40 +00:00
|
|
|
void setCheckURL(const char* host);
|
2019-12-15 06:58:11 +00:00
|
|
|
void setupAsync(const char* host);
|
2020-01-04 07:13:40 +00:00
|
|
|
void execAsyncHTTPcheck();
|
2019-12-15 06:58:11 +00:00
|
|
|
bool decodeResponse(String payload);
|
|
|
|
bool decodeResponse(char* resp);
|
2020-03-25 09:28:12 +00:00
|
|
|
void process();
|
|
|
|
void queueDLdata(asyncHTTPrequest* request);
|
2019-12-15 06:58:11 +00:00
|
|
|
|
2019-07-25 11:27:57 +00:00
|
|
|
private:
|
|
|
|
String getHeaderValue(String header, String headerName);
|
|
|
|
String getDeviceID();
|
|
|
|
String _firwmareType;
|
|
|
|
int _firwmareVersion;
|
2019-08-03 02:42:49 +00:00
|
|
|
int _newVersion;
|
2020-01-04 07:13:40 +00:00
|
|
|
String _checkURL;
|
2019-07-25 11:27:57 +00:00
|
|
|
String _host;
|
|
|
|
String _bin;
|
|
|
|
int _port;
|
|
|
|
std::function<bool(int)> _onComplete;
|
|
|
|
std::function<void()> _onSuccess;
|
|
|
|
std::function<void()> _onFail;
|
2020-01-04 07:13:40 +00:00
|
|
|
asyncHTTPrequest _versionTest;
|
2020-03-25 09:28:12 +00:00
|
|
|
QueueHandle_t _queue;
|
|
|
|
String _pollResponse;
|
2020-01-04 07:13:40 +00:00
|
|
|
|
2019-07-25 11:27:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|