Prepare OTA execution
This commit is contained in:
		@@ -1,4 +1,4 @@
 | 
			
		||||
idf_component_register(SRCS "relays.c" "sync_response.c" "jwt.c" "secure_api.c" "http_client.c" "ethernet.c" "unsecure_api.c" "system.c" "crypto.c" "random.c" "storage.c" "main.c"
 | 
			
		||||
idf_component_register(SRCS "ota.c" "relays.c" "sync_response.c" "jwt.c" "secure_api.c" "http_client.c" "ethernet.c" "unsecure_api.c" "system.c" "crypto.c" "random.c" "storage.c" "main.c"
 | 
			
		||||
                        "dev_name.c"
 | 
			
		||||
                    INCLUDE_DIRS ".")
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -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));
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										7
									
								
								esp32_device/main/ota.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										7
									
								
								esp32_device/main/ota.c
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,7 @@
 | 
			
		||||
#include "ota.h"
 | 
			
		||||
 | 
			
		||||
bool ota_perform_update(const char *version)
 | 
			
		||||
{
 | 
			
		||||
    // TODO
 | 
			
		||||
    return false;
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										24
									
								
								esp32_device/main/ota.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										24
									
								
								esp32_device/main/ota.h
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,24 @@
 | 
			
		||||
/**
 | 
			
		||||
 * OTA functions
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#pragma once
 | 
			
		||||
 | 
			
		||||
#include <stddef.h>
 | 
			
		||||
#include <stdbool.h>
 | 
			
		||||
 | 
			
		||||
#ifdef __cplusplus
 | 
			
		||||
extern "C"
 | 
			
		||||
{
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Update device to a desired version
 | 
			
		||||
     *
 | 
			
		||||
     * Returns TRUE in case of success / FALSE otherwise
 | 
			
		||||
     */
 | 
			
		||||
    bool ota_perform_update(const char *version);
 | 
			
		||||
 | 
			
		||||
#ifdef __cplusplus
 | 
			
		||||
}
 | 
			
		||||
#endif
 | 
			
		||||
		Reference in New Issue
	
	Block a user