Facing the HTTPS connection issue.

vadivelan.s@aco.com
Posts: 3
Joined: Mon Jan 30, 2023 9:56 am

Facing the HTTPS connection issue.

Postby vadivelan.s@aco.com » Mon Jan 30, 2023 11:35 am

Hi ,

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
Attachments
Screenshot (74).png
Screenshot (74).png (274.65 KiB) Viewed 1495 times

ESP_YJM
Posts: 300
Joined: Fri Feb 26, 2021 10:30 am

Re: Facing the HTTPS connection issue.

Postby ESP_YJM » Tue Jan 31, 2023 6:22 am

0x4290 means MBEDTLS_ERR_RSA_PUBLIC_FAILED(0x4280) + MBEDTLS_ERR_MPI_ALLOC_FAILED(0x0010). Maybe you're running out of memory.

Who is online

Users browsing this forum: axellin and 80 guests