我希望你一切都好。我目前正在开发一个 ESP-IDF 项目,尝试使用 HTTPS 执行 OTA(无线)固件更新。具体来说,我使用的是 ESP-IDF 提供的高级 HTTPS OTA 示例代码。
我的目标是通过从 AWS 托管的 S3 存储桶下载固件二进制文件来更新 ESP32 设备上的固件。我已确保 S3 存储桶具有公共访问权限,并且我已将 helloworld.bin 文件放入其中。
但是,当我运行高级 HTTPS OTA 示例代码并将 URL 替换为我的 S3 存储桶的 URL 时,我遇到以下错误:
I (19042) advanced_https_ota_example: Starting Advanced OTA example
E (19052) esp_https_ota: No option for server verification is enabled in esp_http_client config.
E (19062) advanced_https_ota_example: ESP HTTPS OTA Begin failed
ESP HTTPS OTA 过程似乎在开始阶段失败。我已尝试解决此问题,但不确定如何解决。
有人可以指导我如何解决这个错误吗?此外,如果有更好或替代的方法在 ESP32 设备上实现 OTA 更新,我将不胜感激任何建议或见解。非常感谢您的时间和帮助。
最诚挚的问候, 拉胡尔 B.
为了更好的诊断,您应该启用更多跟踪。为此,请将以下部分添加到您的
platformio.ini
:
build_flags =
-DCORE_DEBUG_LEVEL=5 ; 4=DEBUG, 5=VERBOSE
此外,您需要在运行时启用该日志级别,请在 ota 任务开始时
esp_log_level_set
:
void advanced_ota_example_task(void *pvParameter)
{
esp_log_level_set("*", ESP_LOG_VERBOSE);
当它正常工作时,你的输出应该如下所示
[ 7439][V][ssl_client.cpp:68] start_ssl_client(): Starting socket
[ 7494][V][ssl_client.cpp:146] start_ssl_client(): Seeding the random number generator
[ 7503][V][ssl_client.cpp:155] start_ssl_client(): Setting up the SSL/TLS structure...
[ 7511][V][ssl_client.cpp:190] start_ssl_client(): Attaching root CA cert bundle
[ 7524][V][ssl_client.cpp:254] start_ssl_client(): Setting hostname for TLS session...
[ 7532][V][ssl_client.cpp:269] start_ssl_client(): Performing the SSL/TLS handshake...
[ 7559][D][esp_crt_bundle.c:108] esp_crt_verify_callback(): 147 certificates in bundle
[ 7587][I][esp_crt_bundle.c:142] esp_crt_verify_callback(): Certificate validated
[ 8043][D][esp_crt_bundle.c:108] esp_crt_verify_callback(): 147 certificates in bundle
[ 8217][I][esp_crt_bundle.c:142] esp_crt_verify_callback(): Certificate validated
esp_crt_verify_callback()
被调用了 2 次,因为在我的情况下有一个中间 CA。
您可以在任务结束时降低日志级别并在生产版本中将其删除
要使证书捆绑工作,您还需要在
config
结构中启用它并设置成员 .crt_bundle_attach
:
esp_http_client_config_t config = {
.url = CONFIG_EXAMPLE_FIRMWARE_UPGRADE_URL,
.auth_type = HTTP_AUTH_TYPE_NONE,
.timeout_ms = CONFIG_EXAMPLE_OTA_RECV_TIMEOUT,
.max_redirection_count = 5,
.buffer_size = CONFIG_EXAMPLE_HTTP_REQUEST_SIZE, // without setting this, we get an error "esp_https_ota: Reached max_authorization_retries (401)"
.buffer_size_tx = 2048, // TODO: adjust to request length. The github download url is alone 600 bytes long
.crt_bundle_attach = arduino_esp_crt_bundle_attach,
.keep_alive_enable = true,
.keep_alive_interval = 30,
.keep_alive_count = 300,
};
此外,我发现在我的环境中,esp_https_ota/src/esp_https_ota.c/esp_https_ota_get_img_desc() 中存在错误。计算出的偏移量是错误的。这可能取决于您的环境和版本,例如我正在使用 VSCode+PlatformIO+Arduino 框架。
这是我的环境的修复:
// this line is wrong:
//const int app_desc_offset = sizeof(esp_image_header_t) + sizeof(esp_image_segment_header_t);
// this line works for me
const int app_desc_offset = 32;
迈克尔