fix: https and first ota process

This commit is contained in:
Hendrik Schutter 2021-01-08 23:08:07 +01:00
parent 1ff0de1f49
commit f1fb982e21
3 changed files with 19 additions and 25 deletions

View File

@ -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)

View File

@ -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
{

View File

@ -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