ESP32 http OTA upgrade practical operation

ESP32 http OTA upgrade practical operation

Explanation

ESP32 OTA study record, commented encryption server certificate validation process, carried out http ota test, for your reference.

HTTP server

Software Download link: HFS
Open the software press the icon to add firmware:
Here Insert Picture Description

Coding

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.cThe certificate verification process commented, the other does not require changes

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
Here Insert Picture Description

Note: Before OTA upgrade you need to connect to the wifi, probably log is as follows:
Here Insert Picture Description

Published an original article · won praise 1 · views 147

Guess you like

Origin blog.csdn.net/weixin_40299863/article/details/103903695