@ -91,14 +91,25 @@ esp_err_t errMeshOTAInitialize()
}
}
if ( err = = ESP_OK )
{
xReturned = xTaskCreate ( vTaskOTAWorker , " vTaskOTAWorker " , 8192 , NULL , 5 , NULL ) ;
if ( xReturned ! = pdPASS )
{
ESP_LOGE ( LOG_TAG , " Unable to create the OTA worker task " ) ;
err = ESP_FAIL ;
}
}
return err ;
}
void vAddNodeToPossibleUpdatableQueue ( uint8_t * pu8Data )
void vAddNodeToPossibleUpdatableQueue ( uint8_t * pu8MAC )
{
//send payload to node queue
//send payload to node queues
mesh_addr_t addrNode ;
memcpy ( & addrNode . addr , ( uint8_t * ) pu8Data , 6 ) ; //copy MAC
memcpy ( & addrNode . addr , ( uint8_t * ) pu8MAC , 6 ) ; //copy MAC
if ( xQueueSend ( queueNodes , & addrNode , portMAX_DELAY ) ! = pdPASS )
{
@ -151,11 +162,37 @@ void vChangeStateOfServerWorker(bool bState) //allow access via function ptn to
void vTaskOTAWorker ( void * arg )
{
while ( true )
{
if ( ( uxQueueSpacesAvailable ( queueNodes ) - QUEUE_NODES_SIZE ) = = 0 )
{
//nodes queue is empty
ESP_LOGI ( LOG_TAG , " nodes queue is empty " ) ;
if ( bWantReboot = = true )
{
ESP_LOGI ( LOG_TAG , " ESP32 Reboot ... " ) ;
//vTaskDelay( (1000) / portTICK_PERIOD_MS);
//esp_restart();
}
//read OTAMessages queue
//if OTA_Version_Response
// --> send OTA_Version_Request
// --> this version older --> start OTA_Rx --> vAddAllNeighboursToQueue(); //add all existing neighbours to queues
// --> this version newer --> start OTA_Tx
//if not OTA_Version_Response --> do nothing
}
vTaskDelay ( ( 1000 ) / portTICK_PERIOD_MS ) ;
}
}
void vTaskServerWorker ( void * arg )
@ -193,8 +230,9 @@ void vTaskServerWorker(void *arg)
//set want reboot
ESP_LOGI ( LOG_TAG , " Updated successfully via HTTPS, set pending reboot " ) ;
bWantReboot = true ;
vAddAllNeighboursToQueue ( ) ; //add all existing neighbours to queue (aparent will not be added because this node is the root)
}
vTaskDelay ( ( SERVER_CHECK_INTERVAL * 1000 ) / portTICK_PERIOD_MS ) ; //sleep till next server check
vTaskDelay ( ( SERVER_CHECK_INTERVAL * 1000 ) / portTICK_PERIOD_MS ) ; //sleep till next server checks
}
}
}
@ -404,7 +442,7 @@ esp_err_t errExtractVersionNumber(const char* pu8Data, uint32_t* pu32DataLenght,
return err ;
}
inline void vPrintOTAProgress ( const uint32_t * const pu32TotalImageSize , const uint32_t * const pu32BytesWritten )
void vPrintOTAProgress ( const uint32_t * const pu32TotalImageSize , const uint32_t * const pu32BytesWritten )
{
uint32_t u32Percentage = 0U ;
static uint32_t u32LastPercentage = 0U ;
@ -425,6 +463,29 @@ inline void vPrintOTAProgress(const uint32_t* const pu32TotalImageSize, const ui
}
}
void vAddAllNeighboursToQueue ( void )
{
esp_err_t err = ESP_OK ;
mesh_addr_t addrParent ; //addr of parent node
mesh_addr_t childrenAddr [ CONFIG_MESH_ROUTE_TABLE_SIZE ] ; //array of children attached to this node
uint16_t u16ChildrenSize ; //number of children attached to this node
err = errGetParentNode ( & addrParent ) ;
if ( err = = ESP_OK )
{
vAddNodeToPossibleUpdatableQueue ( addrParent . addr ) ;
}
ERROR_CHECK ( errGetChildren ( childrenAddr , & u16ChildrenSize ) ) ; //get all children
for ( uint16_t u16Index = 0 ; u16Index < u16ChildrenSize ; u16Index + + )
{
vAddNodeToPossibleUpdatableQueue ( childrenAddr [ u16Index ] . addr ) ;
}
}
/*
esp_err_t esp_mesh_ota_send ( mesh_addr_t * dest )
{