0

I'm trying to perform an OTA update with esp-idf by downloading firmware from an S3 bucket. I'm using the following provided snippet:

esp_http_client_config_t config = {
        .url = "https://my-bucket-name-here.s3.amazonaws.com/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 upgrade failed");
}

When put that URL in my browser or wget it, the file downloads fine. However, the download fails on the ESP32. I get the following message:

␛[0;31mE (1043) esp-tls: couldn't get hostname for :my-bucket-name-here.s3.amazonaws.com:␛[0m
␛[0;31mE (1053) esp-tls: Failed to open new connection␛[0m>
␛[0;31mE (1063) TRANS_SSL: Failed to open a new connection␛[0m
␛[0;31mE (1063) HTTP_CLIENT: Connection failed, sock < 0␛[0m
␛[0;31mE (1073) esp_https_ota: Failed to open HTTP connection: ERROR␛[0m
␛[0;31mE (1073) esp_https_ota: Failed to establish HTTP connection␛[0m
␛[0;31mE (1083) subpub: Firmware upgrade failed␛[0m

I was able to track it down to the function that throws the first error. It's thrown by resolve_host_name() in esp_tls.c here. Specifically, the error occurs in this chunk of code:

if (getaddrinfo(use_host, NULL, &hints, address_info)) {
    ESP_LOGE(TAG, "couldn't get hostname for :%s:", use_host);
    free(use_host);
    return ESP_ERR_ESP_TLS_CANNOT_RESOLVE_HOSTNAME;
}

Any clue why getaddrinfo wouldn't be able to resolve an S3 bucket address? I thought I might have used the wrong certificate, but this seems to be before the certificate is even used.

rcole
  • 96
  • 6

2 Answers2

1

Can you log your Heap sizes before and after the request.

esp_get_free_heap_size();
esp_get_minimum_free_heap_size();

You would need probably 40K of heap available before making https/tls request.

  • I have about 22K available before and after, but even before WiFi initialization I only have 26K. I realized that it's attempting to make the request before WiFi is connected, so now I'm getting a url parse error. Progress! – rcole Aug 07 '20 at 19:42
1

If anyone from the future runs into this problem while trying the example from esp-idf, the problem is that xTaskCreate(&simple_ota_example_task, "ota_example_task", 8192, NULL, 5, NULL); is called before wifi is fully set up. I have an event_handler function for wifi, and creating the task after a SYSTEM_EVENT_STA_GOT_IP event worked for me.

rcole
  • 96
  • 6