I'm facing the HTTPS connection issue
Code: Select all
[Codebox=c file=Untitled.c]void check_update_task(void *pvParameter)
{
while(1)
{
printf("Looking for a new firmware...\n");
// configure the esp_http_client
esp_http_client_config_t config =
{
.url = (char *)UPDATE_JSON_URL,
.method = HTTP_METHOD_GET,
.event_handler = _http_event_handler,
.transport_type = HTTP_TRANSPORT_OVER_SSL, // enabled transport layer over SSL
.cert_pem = (char *) server_cert_aco_pem_start // Then member of variable for the SSL certifications
};
esp_http_client_handle_t client = esp_http_client_init(&config);
// downloading the json file
esp_err_t err = esp_http_client_perform(client);
if(err == ESP_OK)
{
// parse the json file
cJSON *json = cJSON_Parse(rcv_buffer);
if(json == NULL)
{
printf("downloaded file is not a valid json, aborting...\n");
update_ota_status(NOT_VALID_JSON_FILE);
}
else
{
cJSON *version = cJSON_GetObjectItemCaseSensitive(json, "version");
cJSON *file = cJSON_GetObjectItemCaseSensitive(json, "file");
// check the version
if(!cJSON_IsNumber(version))
{
printf("unable to read new version, aborting...\n");
update_ota_status(JSON_VER_FORMAT_INCORRECT);
}
else
{
double new_version = version->valuedouble;
if(new_version > FIRMWARE_VERSION)
{
printf("current firmware version (%.1f) is lower than the available one (%.1f), upgrading...\n", FIRMWARE_VERSION, new_version);
if(cJSON_IsString(file) && (file->valuestring != NULL))
{
printf("downloading and installing new firmware (%s)...\n", file->valuestring);
/* indication to BLE APP */
update_ota_status(OTA_COMMAND_ACCEPTED);
esp_http_client_config_t ota_client_config =
{
.url = file->valuestring,
.cert_pem = server_cert_aco_pem_start,
};
esp_err_t ret = esp_https_ota(&ota_client_config);
if (ret == ESP_OK)
{
printf("OTA OK, restarting...\n");
update_ota_status(OTA_SUCCESS);
//esp_restart();
} else
{
printf("OTA failed...\n");
printf("Error (%s) reading!\n", esp_err_to_name(ret));
update_ota_status(OTA_FAIL_DURING_FLASH);
}
}
else
{
printf("unable to read the new file name, aborting...\n");
update_ota_status(UNABLE_TO_READ_BIN);
}
}
else
{
printf("current firmware version (%.1f) is greater or equal to the available one (%.1f), nothing to do...\n", FIRMWARE_VERSION, new_version);
update_ota_status(DEVICE_UPTODATE);
}
}
}
}
else
{
printf("unable to connect to internet, aborting...\n");
update_ota_status(POOR_INTERNET_CON);
}
// cleanup
esp_http_client_cleanup(client);
printf("\n");
vTaskDelay(20000 / portTICK_PERIOD_MS);
}
}
[/Codebox]
The source code fails with PPOOR_INTERNET_CON error
error is
Looking for a new firmware...
W (54943) wifi:<ba-add>idx:0 (ifx:0, f6:01:33:86:e4:13), tid:0, ssn:3, winSize:64
E (55873) esp-tls-mbedtls: mbedtls_ssl_handshake returned -0x4290
I (55873) esp-tls-mbedtls: Certificate verified.
E (55873) esp-tls: Failed to open new connection
E (55883) TRANSPORT_BASE: Failed to open a new connection
E (55893) HTTP_CLIENT: Connection failed, sock < 0
unable to connect to internet, aborting...
Please help me on this issue .
Thank you