added before OTA update hook

This commit is contained in:
Bogdan Pilyugin 2023-03-17 16:07:51 +02:00
parent 6cf7f4e4a9
commit 25f0da56f8
2 changed files with 9 additions and 1 deletions

View File

@ -108,6 +108,7 @@ void GetRFC3339Time(char *t);
void StartTimeGet(void); void StartTimeGet(void);
esp_err_t StartOTA(void); esp_err_t StartOTA(void);
void regHookBeforeUpdate(void (*before_update)(void));
char* GetAvailVersion(); char* GetAvailVersion();
char* GetUpdateStatus(); char* GetUpdateStatus();

View File

@ -48,6 +48,12 @@ char FwUpdStatus[64] = "<div class='clok'>Updated</div>";
#define HASH_LEN 32 #define HASH_LEN 32
#define REPORT_PACKETS_EVERY 100 #define REPORT_PACKETS_EVERY 100
void (*HookBeforeUpdate)(void);
void regHookBeforeUpdate(void (*before_update)(void))
{
HookBeforeUpdate = before_update;
}
esp_err_t _http_event_handler(esp_http_client_event_t *evt) esp_err_t _http_event_handler(esp_http_client_event_t *evt)
{ {
switch (evt->event_id) switch (evt->event_id)
@ -174,6 +180,7 @@ esp_err_t my_esp_https_ota(const esp_http_client_config_t *config)
if (need_to_update) if (need_to_update)
{ {
ESP_LOGW(TAG, "New firmware has newer build, START update firmware"); ESP_LOGW(TAG, "New firmware has newer build, START update firmware");
HookBeforeUpdate();
int countPackets = 0; int countPackets = 0;
while (1) while (1)
{ {
@ -304,7 +311,7 @@ esp_err_t StartOTA(void)
} }
ESP_LOGI(TAG, "Starting OTA Task"); ESP_LOGI(TAG, "Starting OTA Task");
strcpy(FwUpdStatus, "<div class='clwarn'>Start update...</div>"); strcpy(FwUpdStatus, "<div class='clwarn'>Start update...</div>");
xTaskCreate(OTATask, "OTATask", 1024 * 8, (void*) 0, 3, NULL); xTaskCreate(OTATask, "OTATask", 1024 * 8, (void*) 0, 5, NULL);
return ESP_OK; return ESP_OK;
} }