ESP32 http OTA 升级实操

ESP32 http OTA 升级实操

说明

ESP32 OTA学习记录,注释掉服务器证书加密验证过程,进行http ota测试,供大家参考。

HTTP服务器

软件下载链接:hfs
打开软件后按图示添加固件:
在这里插入图片描述

代码编写

my_ota.c.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "esp_log.h"
#include "esp_err.h"
#include "esp_system.h"
#include "esp_https_ota.h"
#include "my_ota.h"

#define TAG "my_ota"

void test_ota_start(void)
{
	const esp_http_client_config_t config = {
		.url = "http://192.168.1.101:8000/hello-world.bin",
	};
	esp_err_t err = esp_https_ota(&config);
	if(err != ESP_OK){
		ESP_LOGE(TAG, "test_ota fail err:0x%x", err);
	}else{
		ESP_LOGI(TAG, "test_ota success");
		esp_restart();
	}
}

my_ota.h.

#ifndef _MY_OTA_H_
#define _MY_OTA_H_

void test_ota_start(void);

#endif

esp-idf\components\esp_https_ota\src\esp_https_ota.c.将证书验证过程注释掉,其他的不需要改动

esp_err_t esp_https_ota(const esp_http_client_config_t *config)
{
   ...
   ...
#if 0
    if (!config->cert_pem && !config->use_global_ca_store) {
        ESP_LOGE(TAG, "Server certificate not found, either through configuration or global CA store");
        return ESP_ERR_INVALID_ARG;
    }
#endif
    ...
    ...
#if 0
    if (esp_http_client_get_transport_type(client) != HTTP_TRANSPORT_OVER_SSL) {
        ESP_LOGE(TAG, "Transport is not over HTTPS");
        return ESP_FAIL;
    }
#endif
	...
	...
}

make menuconfig
在这里插入图片描述

注意:在OTA升级之前需要先连上wifi,大概日志如下:
在这里插入图片描述

发布了1 篇原创文章 · 获赞 1 · 访问量 147

猜你喜欢

转载自blog.csdn.net/weixin_40299863/article/details/103903695