From f1fb982e21013dab481abdefff9657450f128ee9 Mon Sep 17 00:00:00 2001 From: localhorst Date: Fri, 8 Jan 2021 23:08:07 +0100 Subject: [PATCH] fix: https and first ota process --- components/mesh_ota/https_client.c | 10 ++-------- main/main.c | 32 +++++++++++++++--------------- sdkconfig | 2 +- 3 files changed, 19 insertions(+), 25 deletions(-) diff --git a/components/mesh_ota/https_client.c b/components/mesh_ota/https_client.c index 1f9fb0f..f4a1598 100644 --- a/components/mesh_ota/https_client.c +++ b/components/mesh_ota/https_client.c @@ -74,19 +74,17 @@ https_client_ret_t https_clientRetrieveData(char* pu8Data, uint32_t* pu32DataLen int32_t i32RetRetrieveData = ESP_OK; bzero(pu8Data, *pu32DataLenght); bool bRetriveData = true; + *pu32BytesRead = 0U; while (bRetriveData) { //Reading HTTP response - i32RetRetrieveData = mbedtls_ssl_read(&sHTTPS_ClientConfig.ssl, (unsigned char *)pu8Data, *pu32DataLenght); + i32RetRetrieveData = mbedtls_ssl_read(&sHTTPS_ClientConfig.ssl, (unsigned char *)(pu8Data+(*pu32BytesRead)), ((*pu32DataLenght)-(*pu32BytesRead))); - printf("HTTPSread: %i\n", i32RetRetrieveData); - if(i32RetRetrieveData > 0) { //Data received *pu32BytesRead = *pu32BytesRead + i32RetRetrieveData; - *pu32DataLenght = *pu32DataLenght - *pu32BytesRead; if(*pu32DataLenght > 0) { @@ -106,10 +104,6 @@ https_client_ret_t https_clientRetrieveData(char* pu8Data, uint32_t* pu32DataLen bRetriveData = false; pu32BytesRead = 0; - printf("finished HTTPSread: %i\n", i32RetRetrieveData); - - while(1){} - } if(i32RetRetrieveData == MBEDTLS_ERR_SSL_PEER_CLOSE_NOTIFY) diff --git a/main/main.c b/main/main.c index 33da1af..0c53755 100644 --- a/main/main.c +++ b/main/main.c @@ -508,24 +508,24 @@ static void test(void *pvParameters) https_clientInitialize(); - //https_clientRetrieveData(buffer, &u32BufferLenght, &u32BytesRead); + https_clientRetrieveData(buffer, &u32BufferLenght, &u32BytesRead); - //ESP_LOGI(MESH_TAG, "Data received: %i", u32BytesRead); + ESP_LOGI(MESH_TAG, "Data received: %i", u32BytesRead); - //err = errExtractVersionNumber(buffer, &u32BytesRead, pcRemoteVersionNumber); + err = errExtractVersionNumber(buffer, &u32BytesRead, pcRemoteVersionNumber); if(err == ESP_OK) { - //if(bNewerVersion((curPartitionDesc).version, pcRemoteVersionNumber)) - // { + if(bNewerVersion((curPartitionDesc).version, pcRemoteVersionNumber)) + { ESP_LOGI(MESH_TAG, "Newer Version available"); //write ota - // const esp_partition_t * currentPartition = esp_ota_get_boot_partition(); - //const esp_partition_t * otaPartition = esp_ota_get_next_update_partition(currentPartition); + const esp_partition_t * currentPartition = esp_ota_get_boot_partition(); + const esp_partition_t * otaPartition = esp_ota_get_next_update_partition(currentPartition); - //static esp_ota_handle_t otaHandle; - // uint32_t u32StartOffset = 305; //TODO fix this + static esp_ota_handle_t otaHandle; + uint32_t u32StartOffset = 305; //TODO fix this /* //esp_err_t err = errFindImageStart(pu8Data, pu32DataLenght, &u32StartOffset); @@ -538,13 +538,13 @@ static void test(void *pvParameters) } */ - // ESP_LOGI(MESH_TAG, "first byte offset: %i", u32StartOffset); - //ESP_LOGI(MESH_TAG, "first byte: %x", buffer[u32StartOffset]); + ESP_LOGI(MESH_TAG, "first byte offset: %i", u32StartOffset); + ESP_LOGI(MESH_TAG, "first byte: %x", buffer[u32StartOffset]); - // err = esp_ota_begin(otaPartition, OTA_SIZE_UNKNOWN, &otaHandle); - // ESP_ERROR_CHECK(err); - + err = esp_ota_begin(otaPartition, OTA_SIZE_UNKNOWN, &otaHandle); + ESP_ERROR_CHECK(err); + /* bool stop = false; while(stop == false) @@ -559,7 +559,7 @@ static void test(void *pvParameters) ESP_LOGI(MESH_TAG, "END"); - /* + */ do { @@ -589,7 +589,7 @@ static void test(void *pvParameters) { ESP_LOGI(MESH_TAG, "NO newer Version available"); } - */ + } else { diff --git a/sdkconfig b/sdkconfig index 7b06f80..a9c6b23 100644 --- a/sdkconfig +++ b/sdkconfig @@ -159,7 +159,7 @@ CONFIG_MESH_AP_CONNECTIONS=6 CONFIG_MESH_ROUTE_TABLE_SIZE=50 CONFIG_OTA_HTTPS_SERVER_COMMON_NAME="ota.hendrikschutter.com" CONFIG_OTA_HTTPS_SERVER_PORT="443" -CONFIG_OTA_HTTPS_URL="https://ota.hendrikschutter.com/hex.txt" +CONFIG_OTA_HTTPS_URL="https://ota.hendrikschutter.com/hello-world.bin" CONFIG_OTA_HTTPS_AUTH="b3RhOnB3" # end of Mesh OTA Configuration