Prepare OTA execution

This commit is contained in:
2024-10-05 20:28:55 +02:00
parent 80452e10de
commit f4dda44d15
5 changed files with 61 additions and 2 deletions

@ -12,6 +12,7 @@
#include "ethernet.h"
#include "constants.h"
#include "relays.h"
#include "ota.h"
static const char *TAG = "main";
@ -206,6 +207,32 @@ void app_main(void)
sync_response_print(res);
// Check for firmware update
if (res->available_update)
{
ESP_LOGI(TAG, "Will perform system upgrade to version %s!", res->available_update);
relays_turn_off_all();
secure_api_report_log_message(Info, "Device is starting the OTA procedure...");
if (ota_perform_update(res->available_update))
{
ESP_LOGI(TAG, "OTA update succesfully executed, will reboot...");
secure_api_report_log_message(Info, "Device successfully updated!");
}
else
{
ESP_LOGE(TAG, "OTA update failed! Will reboot...");
secure_api_report_log_message(Error, "Device update failed!");
}
secure_api_report_log_message(Info, "Device will restart after OTA procedure...");
system_sleep(SYNC_TIME_INTERVAL);
reboot();
}
// Update relays configuration
for (size_t i = 0; i < relays_count(); i++)
{
relays_set(i, sync_response_is_relay_on(res, i));