ESP8266_RTOS_SDK: Fail to open HTTP connection in OTA example (GIT8266O-127)

Environment

  • Development Kit: Wemos D1 mini
  • IDF version (git rev-parse --short HEAD to get the commit id.): Latest (2b579ef758a9fc88f76b70cf849652a352dcc555)
  • Development Env: Visual Code / PlatformIo
  • Operating System: Windows
  • Power Supply: USB

Problem Description

E (5885) esp_https_ota: Failed to open HTTP connection: 28675

Expected Behavior

Actual Behavior

Steps to repropduce

Just used provided ota example.

Code to reproduce this issue

/* OTA example

This example code is in the Public Domain (or CC0 licensed, at your option.)

Unless required by applicable law or agreed to in writing, this software is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */ #include “freertos/FreeRTOS.h” #include “freertos/task.h” #include “freertos/event_groups.h”

#include “esp_system.h” #include “esp_wifi.h” #include “esp_event_loop.h” #include “esp_log.h” #include “esp_ota_ops.h” #include “esp_http_client.h” #include “esp_https_ota.h”

#include “nvs.h” #include “nvs_flash.h”

static const char *TAG = “simple_ota_example”; extern const char server_cert_pem_start[] asm(“_binary_src_html_server_pem_start”); //extern const char server_cert_pem_end[] asm(“_binary_src_html_server_pem_end”);

/* FreeRTOS event group to signal when we are connected & ready to make a request */ static EventGroupHandle_t wifi_event_group;

/* The event group allows multiple bits for each event, but we only care about one event - are we connected to the AP with an IP? */ const int CONNECTED_BIT = BIT0;

esp_err_t _http_event_handler(esp_http_client_event_t *evt) { switch(evt->event_id) { case HTTP_EVENT_ERROR: ESP_LOGD(TAG, “HTTP_EVENT_ERROR”); break; case HTTP_EVENT_ON_CONNECTED: ESP_LOGD(TAG, “HTTP_EVENT_ON_CONNECTED”); break; case HTTP_EVENT_HEADER_SENT: ESP_LOGD(TAG, “HTTP_EVENT_HEADER_SENT”); break; case HTTP_EVENT_ON_HEADER: ESP_LOGD(TAG, “HTTP_EVENT_ON_HEADER, key=%s, value=%s”, evt->header_key, evt->header_value); break; case HTTP_EVENT_ON_DATA: ESP_LOGD(TAG, “HTTP_EVENT_ON_DATA, len=%d”, evt->data_len); break; case HTTP_EVENT_ON_FINISH: ESP_LOGD(TAG, “HTTP_EVENT_ON_FINISH”); break; case HTTP_EVENT_DISCONNECTED: ESP_LOGD(TAG, “HTTP_EVENT_DISCONNECTED”); break; } return ESP_OK; }

static esp_err_t event_handler(void *ctx, system_event_t event) { switch (event->event_id) { case SYSTEM_EVENT_STA_START: esp_wifi_connect(); break; case SYSTEM_EVENT_STA_GOT_IP: xEventGroupSetBits(wifi_event_group, CONNECTED_BIT); break; case SYSTEM_EVENT_STA_DISCONNECTED: / This is a workaround as ESP32 WiFi libs don’t currently auto-reassociate. */ esp_wifi_connect(); xEventGroupClearBits(wifi_event_group, CONNECTED_BIT); break; default: break; } return ESP_OK; }

static void initialise_wifi(void) { tcpip_adapter_init(); wifi_event_group = xEventGroupCreate(); ESP_ERROR_CHECK( esp_event_loop_init(event_handler, NULL) ); wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT(); ESP_ERROR_CHECK( esp_wifi_init(&cfg) ); ESP_ERROR_CHECK( esp_wifi_set_storage(WIFI_STORAGE_RAM) ); wifi_config_t wifi_config = { .sta = { .ssid = “DIGI-Peh2”, .password = “VRjpUfR8”, }, }; ESP_LOGI(TAG, “Setting WiFi configuration SSID %s…”, wifi_config.sta.ssid); ESP_ERROR_CHECK( esp_wifi_set_mode(WIFI_MODE_STA) ); ESP_ERROR_CHECK( esp_wifi_set_config(ESP_IF_WIFI_STA, &wifi_config) ); ESP_ERROR_CHECK( esp_wifi_start() ); }

void simple_ota_example_task(void * pvParameter) { ESP_LOGI(TAG, “Starting OTA example…”);

/* Wait for the callback to set the CONNECTED_BIT in the
   event group.
*/
xEventGroupWaitBits(wifi_event_group, CONNECTED_BIT,
                    false, true, portMAX_DELAY);
ESP_LOGI(TAG, "Connect to Wifi ! Start to Connect to Server....");

esp_http_client_config_t config = {
    .url = "https://hostmydream.com/boris/Esp8266/firmware.bin",
    .cert_pem = (char *)server_cert_pem_start,
    .event_handler = _http_event_handler,
};
esp_err_t ret = esp_https_ota(&config);
if (ret == ESP_OK) {
    esp_restart();
} else {
    ESP_LOGE(TAG, "Firmware Upgrades Failed");
}
while (1) {
    vTaskDelay(1000 / portTICK_PERIOD_MS);
}

}

void app_main() { // Initialize NVS. esp_err_t err = nvs_flash_init(); if (err == ESP_ERR_NVS_NO_FREE_PAGES) { // OTA app partition table has a smaller NVS partition size than the non-OTA // partition table. This size mismatch may cause NVS initialization to fail. // If this happens, we erase NVS partition and initialize NVS again. ESP_ERROR_CHECK(nvs_flash_erase()); err = nvs_flash_init(); } ESP_ERROR_CHECK( err );

initialise_wifi();
xTaskCreate(&simple_ota_example_task, "ota_example_task", 8192, NULL, 5, NULL);

}

Debug Logs

I (1015) simple_ota_example: Setting WiFi configuration SSID DIGI-Peh2… D (1025) event: SYSTEM_EVENT_STA_START V (1035) event: enter default callback V (1035) event: exit default callback I (1045) simple_ota_example: Starting OTA example… D (1575) event: SYSTEM_EVENT_STA_CONNECTED, ssid:DIGI-Peh2, ssid_len:9, bssid:60🇩🇪f3:26:38:08, channel:4, authmode:3 V (1575) event: enter default callback D (1585) tcpip_adapter: dhcp client init ip/mask/gw to all-0 D (1585) tcpip_adapter: if0 start ip lost tmr: enter D (1595) tcpip_adapter: if0 start ip lost tmr: no need start because netif=0x40106d24 interval=120 ip=0 D (1615) udp_sync: UDP sync cache udp 0x40106de4 D (1615) udp_sync: UDP sync clear udp 0x40106de4 D (1625) tcpip_adapter: dhcp client start successfully V (1635) event: exit default callback D (2125) tcpip_adapter: dhcpc time(ms): 0

D (2625) tcpip_adapter: dhcpc time(ms): 500

D (3125) tcpip_adapter: dhcpc time(ms): 1000

D (3345) udp_sync: UDP sync cache udp 0x40106de4 D (3345) udp_sync: UDP sync clear udp 0x40106de4 D (3625) tcpip_adapter: dhcpc time(ms): 1500

D (3625) udp_sync: UDP sync cache udp 0x40106de4 D (3635) udp_sync: UDP sync clear udp 0x40106de4 D (4125) tcpip_adapter: dhcpc time(ms): 2000

D (4625) tcpip_adapter: if0 dhcpc cb D (4625) tcpip_adapter: if0 ip changed=1 D (4625) event: SYSTEM_EVENT_STA_GOT_IP, ip:192.168.100.20, mask:255.255.255.0, gw:192.168.100.1 V (4625) event: enter default callback I (4635) event: sta ip: 192.168.100.20, mask: 255.255.255.0, gw: 192.168.100.1 V (4645) event: exit default callback I (4655) simple_ota_example: Connect to Wifi ! Start to Connect to Server… D (4665) HTTP_CLIENT: Begin connect to: https://hostmydream.com:443 D (4665) esp-tls: host:hostmydream.com: strlen 15 D (4675) udp_sync: UDP sync cache udp 0x40107648 D (4685) udp_sync: UDP sync clear udp 0x40107648 D (4695) tcpip_adapter: ip:192.168.100.20,mask:255.255.255.0,gw:192.168.100.1

D (4705) udp_sync: UDP sync close port 43888 D (4805) esp-tls: handshake in progress… D (5805) simple_ota_example: HTTP_EVENT_ON_CONNECTED D (5815) HTTP_CLIENT: Write header[3]: GET /boris/Esp8266/firmware.bin HTTP/1.1 User-Agent: ESP32 HTTP Client/1.0 Host: hostmydream.com Content-Length: 0

W (5825) TRANS_SSL: Poll timeout or error, errno=Success, fd=54, timeout_ms=5000 E (5835) HTTP_CLIENT: Error write request D (5835) simple_ota_example: HTTP_EVENT_DISCONNECTED D (5885) simple_ota_example: HTTP_EVENT_DISCONNECTED E (5885) esp_https_ota: Failed to open HTTP connection: 28675 E (5885) simple_ota_example: Firmware Upgrades Failed

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 24

Most upvoted comments

I am sorry that the application binary must located at place before offset “2MB”, and I see you place it at “0x210000”. Now the SDK does not support factory binary, so you can remove it and move the 2 OTAs partitions the previous place.