Skip to content

Commit

Permalink
OTA project name check, url, and static user agent
Browse files Browse the repository at this point in the history
  • Loading branch information
ma-lwa-re committed Jun 26, 2022
1 parent 76b1dfe commit 2d68ae0
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
6 changes: 3 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ set(OTA_UPDATES ON)
set(PROJECT_VER "2.4.0.2")

if(HOME_AUTOMATION STREQUAL "HOMEKIT")
set(EXTRA_COMPONENT_DIRS ${CMAKE_CURRENT_LIST_DIR}/../esp-apple-homekit-adk/)
set(EXTRA_COMPONENT_DIRS $ENV{IDF_PATH}/../esp-apple-homekit-adk/)
elseif(HOME_AUTOMATION STREQUAL "NEST")
set(EXTRA_COMPONENT_DIRS ${CMAKE_CURRENT_LIST_DIR}/../esp-google-iot/)
set(EXTRA_COMPONENT_DIRS $ENV{IDF_PATH}/../esp-google-iot/)
elseif(HOME_AUTOMATION STREQUAL "ALEXA")
set(EXTRA_COMPONENT_DIRS ${CMAKE_CURRENT_LIST_DIR}/../esp-aws-iot/)
set(EXTRA_COMPONENT_DIRS $ENV{IDF_PATH}/../esp-aws-iot/)
endif()

include($ENV{IDF_PATH}/tools/cmake/project.cmake)
Expand Down
10 changes: 6 additions & 4 deletions main/ota.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,6 @@ const char *LETS_ENCRYPT_X1_ROOT_CA = "-----BEGIN CERTIFICATE-----\n"
"emyPxgcYxn/eR44/KJ4EBs+lVDR3veyJm+kXQ99b21/+jh5Xos1AnX5iItreGCc=\n"
"-----END CERTIFICATE-----";

char *ota_user_agent;

void print_app_desc(esp_app_desc_t app_desc, char *app, esp_log_level_t log_level) {
ESP_LOG_LEVEL(log_level, OTA_TAG, "%s firmware project: %s", app, app_desc.project_name);
ESP_LOG_LEVEL(log_level, OTA_TAG, "%s firmware version: %s", app, app_desc.version);
Expand All @@ -83,7 +81,7 @@ esp_err_t validate_image_header(esp_https_ota_handle_t *https_ota_handle) {
esp_http_client_config_t config = {
.url = OTA_UPDATE_URL,
.cert_pem = LETS_ENCRYPT_X1_ROOT_CA,
.user_agent = ota_user_agent
.user_agent = OTA_UPDATE_USER_AGENT
};

esp_https_ota_config_t ota_config = {
Expand Down Expand Up @@ -114,6 +112,11 @@ esp_err_t validate_image_header(esp_https_ota_handle_t *https_ota_handle) {

print_app_desc(update_app_info, "Update", ESP_LOG_WARN);

if(memcmp(update_app_info.project_name, running_app_info.project_name, sizeof(update_app_info.project_name)) != 0) {
ESP_LOGE(OTA_TAG, "Invalid project name!");
return ESP_FAIL;
}

if(memcmp(update_app_info.version, running_app_info.version, sizeof(update_app_info.version)) <= 0) {
ESP_LOGI(OTA_TAG, "Running firmware version is up to date!");
return ESP_ERR_INVALID_VERSION;
Expand All @@ -128,7 +131,6 @@ esp_err_t validate_image_header(esp_https_ota_handle_t *https_ota_handle) {
}

void ota_task(void *arg) {
asprintf(&ota_user_agent, "%s - %s v%s", OTA_UPDATE_USER_AGENT, OTA_PROJECT_NAME, OTA_PROJECT_VER);
vTaskDelay(SLEEP_INTERVAL_10_SEC / portTICK_PERIOD_MS);

for(;;) {
Expand Down
6 changes: 2 additions & 4 deletions main/ota.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,8 @@
#include "esp_ota_ops.h"
#include "esp_https_ota.h"

#define OTA_PROJECT_NAME (PROJECT_NAME)
#define OTA_PROJECT_VER (PROJECT_VER)
#define OTA_UPDATE_URL ("https://ma.lwa.re/ota/Dreamdesk.bin")
#define OTA_UPDATE_USER_AGENT ("ESP32 HTTP Client/1.0")
#define OTA_UPDATE_URL ("https://ma.lwa.re/ota/" PROJECT_NAME ".bin")
#define OTA_UPDATE_USER_AGENT ("ESP32 HTTP Client/1.0 - " PROJECT_NAME " v" PROJECT_VER)
#define SLEEP_INTERVAL_10_SEC (1000 * 10)
#define SLEEP_INTERVAL_12_HOURS (1000 * 60 * 60 * 12)

Expand Down

0 comments on commit 2d68ae0

Please sign in to comment.