ESP32-OTA-Updater
Loading...
Searching...
No Matches
ESP32_OTA_Updater.h
1#ifndef ESP32_OTA_UPDATER_H_
2#define ESP32_OTA_UPDATER_H_
8#include <WString.h>
9#include <WiFi.h>
10#include <WiFiClientSecure.h>
11#include <HTTPClient.h>
12
13#include "Errors.h"
14#include "SemanticVersion.h"
15
16#define ESP32_OTA_UPDATER_SHORTSTRING_LENGTH 50
17#define ESP32_OTA_UPDATER_LONGSTRING_LENGTH 150
18
27{
28private:
29 char repositry_owner[ESP32_OTA_UPDATER_SHORTSTRING_LENGTH];
30 char repositry_name[ESP32_OTA_UPDATER_SHORTSTRING_LENGTH];
31 char gh_api_key[ESP32_OTA_UPDATER_LONGSTRING_LENGTH];
32 bool api_key_defined;
33 char firmware_asset_path[ESP32_OTA_UPDATER_SHORTSTRING_LENGTH];
34 const char *http_useragent = "ESP32-OTA-Updater";
35
36 bool new_version_available = false;
37 char binary_download_url[ESP32_OTA_UPDATER_LONGSTRING_LENGTH];
38 int binary_size = 0;
40 const Version current_version;
41 ESP32_OTA_Updater_Error error;
42 WiFiClientSecure wifi_client_secure;
43 HTTPClient http_client;
45 const char *rootCert;
46
47 void updateProgressCallback(size_t progress, size_t size);
48 int httpclientSendRequest(HTTPClient &http_client);
49 inline void _begin(const char *owner, const char *repo, const char *firmware_path);
50
51 Print *debugPrinter = NULL;
52 void debugf(const char *format, ...);
53
54public:
66 ESP32_OTA_Updater(const char *rootCertificate, const char *current_version);
67
78 bool begin(const char *owner, const char *repo, const char *firmware_path, const char *api_key);
79
89 bool begin(const char *owner, const char *repo, const char *firmware_path);
90
99 bool available();
100
108 bool downloadAndInstall();
109
113 void reboot();
114
122 ESP32_OTA_Updater_Error getErrorCode();
130 String getErrorDescription();
131
138 void setDebug(Print *debugStream);
139};
140
141#endif
Contains the declaration of the Version class.
Class for performing Over-The-Air (OTA) updates on ESP32 devices, with Github Actions and Releases.
Definition ESP32_OTA_Updater.h:27
void setDebug(Print *debugStream)
Sets the debug output stream for logging messages.
Definition ESP32_OTA_Updater.cpp:316
bool downloadAndInstall()
Downloads and installs the firmware update. Use 'reboot()' for the esp to reboot and the update to ta...
Definition ESP32_OTA_Updater.cpp:188
bool begin(const char *owner, const char *repo, const char *firmware_path, const char *api_key)
Initializes the ESP32 OTA Updater.
Definition ESP32_OTA_Updater.cpp:11
String getErrorDescription()
Returns the description of the last error that occurred.
Definition ESP32_OTA_Updater.cpp:275
void reboot()
Initiates a reboot of the esp32, which effectively finished a previously installed update.
Definition ESP32_OTA_Updater.cpp:264
ESP32_OTA_Updater_Error getErrorCode()
Get the error code.
Definition ESP32_OTA_Updater.cpp:270
bool available()
Checks if a firmware update is available.
Definition ESP32_OTA_Updater.cpp:95
Represents a semantic version.
Definition SemanticVersion.h:17