feat: add OTA firmware update from URL
Wraps esp_https_ota for over-the-air updates via HTTPS. Dual OTA partitions enable safe rollback. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
33
main/ota/ota_manager.c
Normal file
33
main/ota/ota_manager.c
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
#include "ota_manager.h"
|
||||||
|
|
||||||
|
#include "esp_log.h"
|
||||||
|
#include "esp_ota_ops.h"
|
||||||
|
#include "esp_http_client.h"
|
||||||
|
#include "esp_https_ota.h"
|
||||||
|
|
||||||
|
static const char *TAG = "ota";
|
||||||
|
|
||||||
|
esp_err_t ota_update_from_url(const char *url)
|
||||||
|
{
|
||||||
|
ESP_LOGI(TAG, "Starting OTA from: %s", url);
|
||||||
|
|
||||||
|
esp_http_client_config_t config = {
|
||||||
|
.url = url,
|
||||||
|
.timeout_ms = 120000,
|
||||||
|
.buffer_size = 4096,
|
||||||
|
};
|
||||||
|
|
||||||
|
esp_https_ota_config_t ota_config = {
|
||||||
|
.http_config = &config,
|
||||||
|
};
|
||||||
|
|
||||||
|
esp_err_t ret = esp_https_ota(&ota_config);
|
||||||
|
if (ret == ESP_OK) {
|
||||||
|
ESP_LOGI(TAG, "OTA successful, restarting...");
|
||||||
|
esp_restart();
|
||||||
|
} else {
|
||||||
|
ESP_LOGE(TAG, "OTA failed: %s", esp_err_to_name(ret));
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
12
main/ota/ota_manager.h
Normal file
12
main/ota/ota_manager.h
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "esp_err.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Perform OTA firmware update from a URL.
|
||||||
|
* Downloads the firmware binary and applies it. Reboots on success.
|
||||||
|
*
|
||||||
|
* @param url HTTPS URL to the firmware .bin file
|
||||||
|
* @return ESP_OK on success (device will reboot), error code otherwise
|
||||||
|
*/
|
||||||
|
esp_err_t ota_update_from_url(const char *url);
|
||||||
Reference in New Issue
Block a user