fix in ota upstream to parent and other neighbours
This commit is contained in:
		| @ -189,9 +189,9 @@ void vMeshOtaTaskOTAWorker(void *arg) | ||||
|  | ||||
|             if((uxQueueSpacesAvailable(queueNodes) - QUEUE_NODES_SIZE) == 0) | ||||
|                 { | ||||
|                      ESP_LOGI(LOG_TAG, "//nodes queue is empty"); | ||||
|                     ESP_LOGI(LOG_TAG, "//nodes queue is empty"); | ||||
|  | ||||
|                   xReturned =  xSemaphoreTake(bsOTAProcess, portMAX_DELAY); //wait for binary semaphore that allows to start the OTA process | ||||
|                     xReturned =  xSemaphoreTake(bsOTAProcess, portMAX_DELAY); //wait for binary semaphore that allows to start the OTA process | ||||
|                     if((xReturned == pdTRUE) && (bWantReboot == true) && (OTA_ALLOW_REBOOT == 1)) | ||||
|                         { | ||||
|                             ESP_LOGE(LOG_TAG, "ESP32 Reboot ..."); | ||||
| @ -204,7 +204,7 @@ void vMeshOtaTaskOTAWorker(void *arg) | ||||
|                 } | ||||
|             else | ||||
|                 { | ||||
|                      ESP_LOGI(LOG_TAG, "//queue not empty %i", (uxQueueSpacesAvailable(queueNodes) - QUEUE_NODES_SIZE)); | ||||
|                     ESP_LOGI(LOG_TAG, "//queue not empty %i", (uxQueueSpacesAvailable(queueNodes) - QUEUE_NODES_SIZE)); | ||||
|                     if (xQueueReceive(queueNodes, &meshNodeAddr, ((100) / portTICK_PERIOD_MS)) != pdTRUE) | ||||
|                         { | ||||
|                             ESP_LOGE(LOG_TAG, "Unable to receive OTA Messages from Queue"); | ||||
| @ -231,7 +231,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 | ||||
|                     vMeshOtaUtilAddAllNeighboursToQueue(&meshNodeAddr); //add all existing neighbours to queue | ||||
|                 } | ||||
|             vTaskDelay( (1000) / portTICK_PERIOD_MS); | ||||
|         } | ||||
| @ -262,7 +262,7 @@ esp_err_t errMeshOtaSlaveEndpoint(bool* const cpbNewOTAImage) | ||||
|             //queue not empty | ||||
|             if (xQueueReceive(queueMessageOTA, &sOTAMessage, ((100) / portTICK_PERIOD_MS)) != pdTRUE) | ||||
|                 { | ||||
|                     ESP_LOGE(LOG_TAG, "Unable to receive OTA Messages from Queue"); | ||||
|                     ESP_LOGE(LOG_TAG, "SLAVE: Unable to receive OTA Messages from Queue"); | ||||
|                     err = ESP_FAIL; | ||||
|                 } | ||||
|  | ||||
| @ -279,7 +279,7 @@ esp_err_t errMeshOtaSlaveEndpoint(bool* const cpbNewOTAImage) | ||||
|                     if((bMeshOtaUtilNewerVersion((bootPartitionDesc).version, (char*) sOTAMessage.au8Payload)) && (err == ESP_OK)) //compare local and remote version | ||||
|                         { | ||||
|                             //remote newer as local | ||||
|                             ESP_LOGI(LOG_TAG, "remote image on node is newer --> OTA update required from node \"%x:%x:%x:%x:%x:%x\"", sOTAMessage.meshSenderAddr.addr[0], sOTAMessage.meshSenderAddr.addr[1], sOTAMessage.meshSenderAddr.addr[2], sOTAMessage.meshSenderAddr.addr[3], sOTAMessage.meshSenderAddr.addr[4], sOTAMessage.meshSenderAddr.addr[5]); | ||||
|                             ESP_LOGI(LOG_TAG, "SLAVE: remote image on node is newer --> OTA update required from node \"%x:%x:%x:%x:%x:%x\"", sOTAMessage.meshSenderAddr.addr[0], sOTAMessage.meshSenderAddr.addr[1], sOTAMessage.meshSenderAddr.addr[2], sOTAMessage.meshSenderAddr.addr[3], sOTAMessage.meshSenderAddr.addr[4], sOTAMessage.meshSenderAddr.addr[5]); | ||||
|                             //  --> this version older --> start OTA_Rx --> set cpbNewOTAImage true | ||||
|                             ERROR_CHECK(errMeshOtaPartitionAccessMeshReceive(cpbNewOTAImage, &sOTAMessage.meshSenderAddr)); | ||||
|                         } | ||||
| @ -287,7 +287,7 @@ esp_err_t errMeshOtaSlaveEndpoint(bool* const cpbNewOTAImage) | ||||
|                     if((bMeshOtaUtilNewerVersion((char*) sOTAMessage.au8Payload, (bootPartitionDesc).version)) && (err == ESP_OK)) //compare remote and local version | ||||
|                         { | ||||
|                             //local newer as remote | ||||
|                             ESP_LOGI(LOG_TAG, "remote image on node is older --> OTA send required to node \"%x:%x:%x:%x:%x:%x\"", sOTAMessage.meshSenderAddr.addr[0], sOTAMessage.meshSenderAddr.addr[1], sOTAMessage.meshSenderAddr.addr[2], sOTAMessage.meshSenderAddr.addr[3], sOTAMessage.meshSenderAddr.addr[4], sOTAMessage.meshSenderAddr.addr[5]); | ||||
|                             ESP_LOGI(LOG_TAG, "SLAVE: remote image on node is older --> OTA send required to node \"%x:%x:%x:%x:%x:%x\"", sOTAMessage.meshSenderAddr.addr[0], sOTAMessage.meshSenderAddr.addr[1], sOTAMessage.meshSenderAddr.addr[2], sOTAMessage.meshSenderAddr.addr[3], sOTAMessage.meshSenderAddr.addr[4], sOTAMessage.meshSenderAddr.addr[5]); | ||||
|                             //  --> this version newer --> start OTA_Tx | ||||
|                             ERROR_CHECK(errMeshOtaPartitionAccessMeshTransmit(&sOTAMessage.meshSenderAddr)); | ||||
|                         } | ||||
| @ -334,7 +334,7 @@ esp_err_t errMeshOtaMasterEndpoint(bool* const cpbNewOTAImage, const mesh_addr_t | ||||
|                             //queue not empty | ||||
|                             if (xQueueReceive(queueMessageOTA, &sOTAMessage, ((3000) / portTICK_PERIOD_MS)) != pdTRUE) | ||||
|                                 { | ||||
|                                     ESP_LOGE(LOG_TAG, "Unable to receive OTA Messages from queue"); | ||||
|                                     ESP_LOGE(LOG_TAG, "MASTER: Unable to receive OTA Messages from queue"); | ||||
|                                     err = ESP_FAIL; | ||||
|                                 } | ||||
|  | ||||
| @ -347,7 +347,7 @@ esp_err_t errMeshOtaMasterEndpoint(bool* const cpbNewOTAImage, const mesh_addr_t | ||||
|                                     if((bMeshOtaUtilNewerVersion((bootPartitionDesc).version, (char*) sOTAMessage.au8Payload)) && (err == ESP_OK)) //compare local and remote version | ||||
|                                         { | ||||
|                                             //remote newer as local | ||||
|                                             ESP_LOGI(LOG_TAG, "remote image on node is newer --> OTA update required from node \"%x:%x:%x:%x:%x:%x\"", sOTAMessage.meshSenderAddr.addr[0], sOTAMessage.meshSenderAddr.addr[1], sOTAMessage.meshSenderAddr.addr[2], sOTAMessage.meshSenderAddr.addr[3], sOTAMessage.meshSenderAddr.addr[4], sOTAMessage.meshSenderAddr.addr[5]); | ||||
|                                             ESP_LOGI(LOG_TAG, "MASTER: remote image on node is newer --> OTA update required from node \"%x:%x:%x:%x:%x:%x\"", sOTAMessage.meshSenderAddr.addr[0], sOTAMessage.meshSenderAddr.addr[1], sOTAMessage.meshSenderAddr.addr[2], sOTAMessage.meshSenderAddr.addr[3], sOTAMessage.meshSenderAddr.addr[4], sOTAMessage.meshSenderAddr.addr[5]); | ||||
|                                             //  --> this version older --> start OTA_Rx --> set cpbNewOTAImage true | ||||
|                                             ERROR_CHECK(errMeshOtaPartitionAccessMeshReceive(cpbNewOTAImage, &sOTAMessage.meshSenderAddr)); | ||||
|                                         } | ||||
| @ -355,7 +355,7 @@ esp_err_t errMeshOtaMasterEndpoint(bool* const cpbNewOTAImage, const mesh_addr_t | ||||
|                                     if((bMeshOtaUtilNewerVersion((char*) sOTAMessage.au8Payload, (bootPartitionDesc).version)) && (err == ESP_OK)) //compare remote and local version | ||||
|                                         { | ||||
|                                             //local newer as remote | ||||
|                                             ESP_LOGI(LOG_TAG, "remote image on node is older --> OTA send required to node \"%x:%x:%x:%x:%x:%x\"", sOTAMessage.meshSenderAddr.addr[0], sOTAMessage.meshSenderAddr.addr[1], sOTAMessage.meshSenderAddr.addr[2], sOTAMessage.meshSenderAddr.addr[3], sOTAMessage.meshSenderAddr.addr[4], sOTAMessage.meshSenderAddr.addr[5]); | ||||
|                                             ESP_LOGI(LOG_TAG, "MASTER: remote image on node is older --> OTA send required to node \"%x:%x:%x:%x:%x:%x\"", sOTAMessage.meshSenderAddr.addr[0], sOTAMessage.meshSenderAddr.addr[1], sOTAMessage.meshSenderAddr.addr[2], sOTAMessage.meshSenderAddr.addr[3], sOTAMessage.meshSenderAddr.addr[4], sOTAMessage.meshSenderAddr.addr[5]); | ||||
|                                             //  --> this version newer --> start OTA_Tx | ||||
|                                             ERROR_CHECK(errMeshOtaPartitionAccessMeshTransmit(&sOTAMessage.meshSenderAddr)); | ||||
|                                         } | ||||
| @ -379,7 +379,7 @@ esp_err_t errMeshOtaMasterEndpoint(bool* const cpbNewOTAImage, const mesh_addr_t | ||||
|     if((bNodeIsResponding == false) && (bNodeIsConnected == true)) | ||||
|         { | ||||
|             //add node back to queue if connected and NOT responding | ||||
|             ESP_LOGD(LOG_TAG, "OTA-Master: connected and NOT responding --> add node back to queue "); | ||||
|             ESP_LOGI(LOG_TAG, "OTA-Master: connected and NOT responding --> add node back to queue "); | ||||
|             vMeshOtaUtilAddNodeToPossibleUpdatableQueue(cpcMeshNodeAddr->addr); | ||||
|         } | ||||
|     return err; | ||||
|  | ||||
| @ -89,7 +89,7 @@ esp_err_t errMeshOtaPartitionAccessHttps(bool* const cpbNewOTAImage) | ||||
|                             if(err == ESP_OK) | ||||
|                                 { | ||||
|                                     *cpbNewOTAImage = true; //image validated | ||||
|                                     vMeshOtaUtilAddAllNeighboursToQueue(); //add all existing neighbours to queue (aparent will not be added because this node is the root) | ||||
|                                     vMeshOtaUtilAddAllNeighboursToQueue(NULL); //add all existing neighbours to queue (aparent will not be added because this node is the root) | ||||
|                                 } | ||||
|                         } | ||||
|                     else | ||||
| @ -152,9 +152,13 @@ esp_err_t errMeshOtaPartitionAccessMeshTransmit(const mesh_addr_t* const cpcMesh | ||||
|                     if((OTA_MESH_SEGMENT_SIZE * (u32SegmentCounter+1)) >= pBootPartition->size) //check if last segment | ||||
|                         { | ||||
|                             //last partition image segment --> send OTA_Complete | ||||
|                             ESP_LOGD(LOG_TAG, "OTA-TX: last segment--> send Complete"); | ||||
|                             ESP_LOGI(LOG_TAG, "OTA-TX: last segment--> send Complete"); | ||||
|                             sMeshPacket.type = OTA_Complete; | ||||
|                         } | ||||
|                     else | ||||
|                         { | ||||
|                             ESP_LOGI(LOG_TAG, "OTA-TX:  send data"); | ||||
|                         } | ||||
|                     err = errMeshNetworkSendMeshPacket(cpcMeshNodeAddr, &sMeshPacket); | ||||
|                 } | ||||
|             else | ||||
| @ -191,13 +195,15 @@ esp_err_t errMeshOtaPartitionAccessMeshTransmit(const mesh_addr_t* const cpcMesh | ||||
|                                     bNodeIsResponding = true; | ||||
|                                     break; | ||||
|                                 default: | ||||
|                                     ESP_LOGI(LOG_TAG, "OTA-TX: no ACK or ABORT message received"); | ||||
|                                     break; | ||||
|                                 } | ||||
|                         } | ||||
|                     else if (err == ESP_OK) | ||||
|                         { | ||||
|                             //received from wrong node --> back to queue | ||||
|                             vMeshOtaUtilAddOtaMessageToQueue(&sMeshPacket); | ||||
|                             ESP_LOGI(LOG_TAG, "OTA-TX: //received from wrong node --> back to queue"); | ||||
|                             //vMeshOtaUtilAddOtaMessageToQueue(&sMeshPacket); | ||||
|                             //vTaskDelay( (1000) / portTICK_PERIOD_MS); | ||||
|                         } | ||||
|                 }//end OTA message loop | ||||
|  | ||||
| @ -265,8 +271,10 @@ esp_err_t errMeshOtaPartitionAccessMeshReceive(bool* const cpbNewOTAImage, const | ||||
|                                 { | ||||
|                                 case OTA_Complete: //signal end of this OTA process, fall through because same behavior as OTA_Data | ||||
|                                     bComplete = true; | ||||
|                                     ESP_LOGE(LOG_TAG, "OTA-RX: receives complete"); | ||||
|                                 //fall through | ||||
|                                 case OTA_Data: //data segement received | ||||
|                                     ESP_LOGE(LOG_TAG, "OTA-RX: receives data"); | ||||
|                                     bNodeIsResponding = true; | ||||
|                                     ERROR_CHECK(esp_ota_write(otaHandle, sMeshPacket.au8Payload, OTA_MESH_SEGMENT_SIZE)); | ||||
|                                     u32OTABytesWritten = ((u32SegmentCounter+1) * OTA_MESH_SEGMENT_SIZE); //calc bytes that are written in this ota process | ||||
| @ -274,6 +282,7 @@ esp_err_t errMeshOtaPartitionAccessMeshReceive(bool* const cpbNewOTAImage, const | ||||
|                                     u32Index = QUEUE_MESSAGE_OTA_SIZE; //this will end the loop through all OTA messages | ||||
|                                     break; | ||||
|                                 case OTA_Abort: //abort this OTA process | ||||
|                                     ESP_LOGE(LOG_TAG, "OTA-RX: receives abort"); | ||||
|                                     bAbort = true; | ||||
|                                     bNodeIsResponding = true; | ||||
|                                     ESP_LOGE(LOG_TAG, "OTA-RX: receives abort --> abort this OTA process on this node"); | ||||
| @ -308,6 +317,7 @@ esp_err_t errMeshOtaPartitionAccessMeshReceive(bool* const cpbNewOTAImage, const | ||||
|                                     //no error while ota write --> send OTA_ACK packet | ||||
|                                     sMeshPacket.type = OTA_ACK; | ||||
|                                     err = errMeshNetworkSendMeshPacket(cpcMeshNodeAddr, &sMeshPacket); | ||||
|                                     ESP_LOGE(LOG_TAG, "OTA-RX: sent ACK"); | ||||
|                                 } | ||||
|                         } | ||||
|                     else | ||||
|  | ||||
| @ -268,10 +268,9 @@ void vMeshOtaUtilPrintOtaProgress(const uint32_t* const cpcu32TotalImageSize, co | ||||
| * @author Hendrik Schutter | ||||
| * @date 21.01.2021 | ||||
| */ | ||||
| void vMeshOtaUtilAddAllNeighboursToQueue(void) | ||||
| void vMeshOtaUtilAddAllNeighboursToQueue(const mesh_addr_t* const cpcMeshNodeAddr) | ||||
| { | ||||
|     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 = 0U; //number of children attached to this node | ||||
| @ -280,7 +279,22 @@ void vMeshOtaUtilAddAllNeighboursToQueue(void) | ||||
|  | ||||
|     if(err == ESP_OK) | ||||
|         { | ||||
|             vMeshOtaUtilAddNodeToPossibleUpdatableQueue(addrParent.addr); | ||||
|             if (cpcMeshNodeAddr != NULL) | ||||
|                 { | ||||
|                     if((bMeshNetworkCheckMacEquality(addrParent.addr, cpcMeshNodeAddr->addr))) | ||||
|                         { | ||||
|                             //same node --> don't add | ||||
|                         } | ||||
|                     else | ||||
|                         { | ||||
|                             vMeshOtaUtilAddNodeToPossibleUpdatableQueue(addrParent.addr); | ||||
|                         } | ||||
|                 } | ||||
|             else | ||||
|                 { | ||||
|                     vMeshOtaUtilAddNodeToPossibleUpdatableQueue(addrParent.addr); | ||||
|                 } | ||||
|  | ||||
|         } | ||||
|  | ||||
|     err = ESP_OK; //reset error code | ||||
| @ -289,7 +303,21 @@ void vMeshOtaUtilAddAllNeighboursToQueue(void) | ||||
|  | ||||
|     for (uint16_t u16Index = 0; ((u16Index < u16ChildrenSize) && (err == ESP_OK)); u16Index++) | ||||
|         { | ||||
|             vMeshOtaUtilAddNodeToPossibleUpdatableQueue(childrenAddr[u16Index].addr); | ||||
|             if (cpcMeshNodeAddr != NULL) | ||||
|                 { | ||||
|                     if((bMeshNetworkCheckMacEquality(childrenAddr[u16Index].addr, cpcMeshNodeAddr->addr))) | ||||
|                         { | ||||
|                             //same node --> don't add | ||||
|                         } | ||||
|                     else | ||||
|                         { | ||||
|                             vMeshOtaUtilAddNodeToPossibleUpdatableQueue(childrenAddr[u16Index].addr); | ||||
|                         } | ||||
|                 } | ||||
|             else | ||||
|                 { | ||||
|                     vMeshOtaUtilAddNodeToPossibleUpdatableQueue(childrenAddr[u16Index].addr); | ||||
|                 } | ||||
|         } | ||||
| } | ||||
|  | ||||
| @ -336,13 +364,15 @@ void vMeshOtaUtilClearNeighboursQueue(const mesh_addr_t* const cpcMeshNodeAddr) | ||||
|                         { | ||||
|                             ESP_LOGI(LOG_TAG, "REMOVE_NODE: remove node %x", sNode.addr[5]); | ||||
|                         } | ||||
|                         else | ||||
|                     else | ||||
|                         { | ||||
|                             ESP_LOGI(LOG_TAG, "//node is NOT cpcMeshNodeAddr: %i --> keep it in queue",  sNode.addr[5]); | ||||
|                             vMeshOtaUtilAddNodeToPossibleUpdatableQueue(sNode.addr); | ||||
|                         } | ||||
|  | ||||
|                 }else{ | ||||
|                 } | ||||
|             else | ||||
|                 { | ||||
|                     ESP_LOGI(LOG_TAG, "REMOVE_NODE: queue leer"); | ||||
|                 } | ||||
|         }//end nodes | ||||
|  | ||||
| @ -31,7 +31,7 @@ esp_err_t errMeshOtaUtilFindImageStart(const  char* const cpu8Data, const uint32 | ||||
| esp_err_t errMeshOtaUtilSendOtaVersionRequest(const mesh_addr_t* const cpcMeshReceiverAddr); | ||||
| esp_err_t errMeshOtaUtilSendOtaVersionResponse(const mesh_addr_t* const cpcMeshReceiverAddr); | ||||
| void vMeshOtaUtilPrintOtaProgress(const uint32_t* const cpcu32TotalImageSize, const uint32_t* const cpcu32BytesWritten, const OTA_MESH_ROLE_t ceRole); | ||||
| void vMeshOtaUtilAddAllNeighboursToQueue(void); | ||||
| void vMeshOtaUtilAddAllNeighboursToQueue(const mesh_addr_t* const cpcMeshNodeAddr); | ||||
| void vMeshOtaUtilClearOtaMessageQueue(const mesh_addr_t* const cpcMeshNodeAddr); | ||||
| void vMeshOtaUtilClearNeighboursQueue(const mesh_addr_t* const cpcMeshNodeAddr); | ||||
|  | ||||
|  | ||||
| @ -66,6 +66,10 @@ esp_err_t errBlinkyLEDInitialize(void) | ||||
|     gpio_set_level(GPIO_LED_GREEN, 1); //switch on | ||||
| #endif | ||||
|  | ||||
| #ifndef NEW_VERSION | ||||
|     gpio_set_level(GPIO_LED_GREEN, 0); //switch off | ||||
| #endif | ||||
|  | ||||
|     return err; | ||||
| } | ||||
|  | ||||
| @ -86,11 +90,8 @@ void vGPIOInitialize(void) | ||||
|     //LED as Output | ||||
|     gpio_reset_pin(GPIO_LED_BLUE); | ||||
|     gpio_set_direction(GPIO_LED_BLUE, GPIO_MODE_OUTPUT); | ||||
|  | ||||
| #ifdef NEW_VERSION | ||||
|     gpio_reset_pin(GPIO_LED_GREEN); | ||||
|     gpio_set_direction(GPIO_LED_GREEN, GPIO_MODE_OUTPUT); | ||||
| #endif | ||||
|  | ||||
|     //BTN as Input | ||||
|     gpioConf.intr_type = GPIO_INTR_DISABLE; | ||||
|  | ||||
| @ -20,13 +20,12 @@ | ||||
|  | ||||
| #include "Mesh_OTA.h" | ||||
|  | ||||
| //#define NEW_VERSION | ||||
| #define NEW_VERSION | ||||
|  | ||||
| #define GPIO_BOOT_BTN   0 //GPIO0 (Boot BTN) | ||||
| #define GPIO_LED_BLUE   2 //GPIO2 (internal blue LED in DevKit V1.0) | ||||
| #ifdef NEW_VERSION | ||||
| #define GPIO_LED_GREEN 13 //GPIO13 | ||||
| #endif | ||||
|  | ||||
|  | ||||
| #define GPIO_INPUT_PIN_SEL  (1ULL<<GPIO_BOOT_BTN) | ||||
|  | ||||
|  | ||||
| @ -32,7 +32,7 @@ CONFIG_APP_COMPILE_TIME_DATE=y | ||||
| # CONFIG_APP_EXCLUDE_PROJECT_VER_VAR is not set | ||||
| # CONFIG_APP_EXCLUDE_PROJECT_NAME_VAR is not set | ||||
| CONFIG_APP_PROJECT_VER_FROM_CONFIG=y | ||||
| CONFIG_APP_PROJECT_VER="0.0.26" | ||||
| CONFIG_APP_PROJECT_VER="0.0.40" | ||||
| CONFIG_APP_RETRIEVE_LEN_ELF_SHA=16 | ||||
| # end of Application manager | ||||
|  | ||||
|  | ||||
		Reference in New Issue
	
	Block a user