diff --git a/components/mesh_ota/Mesh_OTA.c b/components/mesh_ota/Mesh_OTA.c index 63aac6a..37ff690 100644 --- a/components/mesh_ota/Mesh_OTA.c +++ b/components/mesh_ota/Mesh_OTA.c @@ -157,11 +157,11 @@ void vMeshOtaTaskOTAWorker(void *arg) //nodes queue is empty ESP_LOGI(LOG_TAG, "nodes queue is empty"); - if(bWantReboot == true) + if((bWantReboot == true) && (OTA_ALLOW_REBOOT == 1)) { - //ESP_LOGI(LOG_TAG, "ESP32 Reboot ..."); - //vTaskDelay( (1000) / portTICK_PERIOD_MS); - //esp_restart(); + ESP_LOGE(LOG_TAG, "ESP32 Reboot ..."); + vTaskDelay( (1000) / portTICK_PERIOD_MS); + esp_restart(); } ERROR_CHECK(errMeshOtaSlaveEndpoint(&bNewOTAImage)); @@ -184,6 +184,11 @@ void vMeshOtaTaskOTAWorker(void *arg) //OTA process faild --> add back to queue vMeshOtaUtilAddNodeToPossibleUpdatableQueue(meshNodeAddr.addr); } + else + { + vMeshOtaUtilClearNeighboursQueue(&meshNodeAddr); //remove this node from queue + } + } if(bNewOTAImage == true) @@ -191,6 +196,7 @@ void vMeshOtaTaskOTAWorker(void *arg) //set want reboot ESP_LOGI(LOG_TAG, "Updated successfully via Mesh, set pending reboot"); bWantReboot = true; + vMeshOtaUtilAddAllNeighboursToQueue(); //add all existing neighbours to queue } vTaskDelay( (1000) / portTICK_PERIOD_MS); diff --git a/components/mesh_ota/Mesh_OTA_Globals.c b/components/mesh_ota/Mesh_OTA_Globals.c index 88bda4f..ab74a46 100644 --- a/components/mesh_ota/Mesh_OTA_Globals.c +++ b/components/mesh_ota/Mesh_OTA_Globals.c @@ -7,7 +7,7 @@ SemaphoreHandle_t bsStartStopServerWorker; //binary semaphore SemaphoreHandle_t bsOTAProcess; //binary semaphore //w: errMeshOTAInitialize; -//r: errMeshOTAInitialize; errMeshOtaPartitionAccessHttps; errMeshOtaPartitionAccessMeshReceive; +//r: errMeshOTAInitialize; errMeshOtaPartitionAccessHttps; errMeshOtaPartitionAccessMeshReceive; const esp_partition_t* pOTAPartition; //pointer to ota partition //w: errMeshOTAInitialize; vMeshOtaTaskOTAWorker; vMeshOtaTaskServerWorker diff --git a/components/mesh_ota/Mesh_OTA_Util.c b/components/mesh_ota/Mesh_OTA_Util.c index c43b016..eba303b 100644 --- a/components/mesh_ota/Mesh_OTA_Util.c +++ b/components/mesh_ota/Mesh_OTA_Util.c @@ -243,6 +243,27 @@ void vMeshOtaUtilClearOtaMessageQueue(const mesh_addr_t* const cpcMeshNodeAddr) }//end OTA message loop } +void vMeshOtaUtilClearNeighboursQueue(const mesh_addr_t* const cpcMeshNodeAddr) +{ + mesh_addr_t sNode; //packet for sending and receiving + for (uint32_t u32Index = 0; (u32Index < QUEUE_MESSAGE_OTA_SIZE); u32Index++) //loop through all OTA messages + { + if (xQueueReceive(queueNodes, &sNode, 0) == pdTRUE) + { + if(!(bMeshNetworkCheckMACEquality(sNode.addr, cpcMeshNodeAddr->addr))) + { + //node is NOT cpcMeshNodeAddr --> keep it in queue + vMeshOtaUtilAddNodeToPossibleUpdatableQueue(cpcMeshNodeAddr->addr); + } + else + { + ESP_LOGI(LOG_TAG, "Removed node 0x%x", cpcMeshNodeAddr->addr[5]); + } + } + }//end OTA message loop +} + + void vMeshOtaUtilAddNodeToPossibleUpdatableQueue(const uint8_t* const cpcu8MAC) { //send payload to node queues diff --git a/components/mesh_ota/include/Mesh_OTA.h b/components/mesh_ota/include/Mesh_OTA.h index eab5377..c15b537 100644 --- a/components/mesh_ota/include/Mesh_OTA.h +++ b/components/mesh_ota/include/Mesh_OTA.h @@ -18,6 +18,7 @@ #define OTA_PROGRESS_LOG_INTERVAL 7U #define OTA_MESH_SEGMENT_SIZE MESH_NETWORK_PAYLOAD_SIZE #define OTA_MESH_TIMEOUT 20000U //in ms +#define OTA_ALLOW_REBOOT 0 #define ERROR_CHECK(x) if (err == ESP_OK) \ { \ diff --git a/components/mesh_ota/include/Mesh_OTA_Util.h b/components/mesh_ota/include/Mesh_OTA_Util.h index dfdeb1d..2518282 100644 --- a/components/mesh_ota/include/Mesh_OTA_Util.h +++ b/components/mesh_ota/include/Mesh_OTA_Util.h @@ -26,6 +26,7 @@ esp_err_t errMeshOtaUtilSendOTAVersionResponse(const mesh_addr_t* const cpcMeshR void vMeshOtaUtilPrintOTAProgress(const uint32_t* const cpcu32TotalImageSize, const uint32_t* const cpcu32BytesWritten, const OTA_MESH_ROLE_t ceRole); void vMeshOtaUtilAddAllNeighboursToQueue(void); void vMeshOtaUtilClearOtaMessageQueue(const mesh_addr_t* const cpcMeshNodeAddr); +void vMeshOtaUtilClearNeighboursQueue(const mesh_addr_t* const cpcMeshNodeAddr); //Handler void vMeshOtaUtilAddNodeToPossibleUpdatableQueue(const uint8_t* const cpcu8MAC);