From 78dbbfaba5376da0dc97cbf64a61a98c05e965d7 Mon Sep 17 00:00:00 2001 From: localhorst Date: Tue, 26 Jan 2021 23:55:53 +0100 Subject: [PATCH 1/4] fix in ota upstream to parent and other neighbours --- components/mesh_ota/Mesh_OTA.c | 22 ++++----- .../mesh_ota/Mesh_OTA_Partition_Access.c | 18 ++++++-- components/mesh_ota/Mesh_OTA_Util.c | 46 +++++++++++++++---- components/mesh_ota/include/Mesh_OTA_Util.h | 2 +- main/Blinky_LED.c | 7 +-- main/Blinky_LED.h | 5 +- sdkconfig | 2 +- 7 files changed, 71 insertions(+), 31 deletions(-) diff --git a/components/mesh_ota/Mesh_OTA.c b/components/mesh_ota/Mesh_OTA.c index 699f5d9..14f5e8d 100644 --- a/components/mesh_ota/Mesh_OTA.c +++ b/components/mesh_ota/Mesh_OTA.c @@ -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; diff --git a/components/mesh_ota/Mesh_OTA_Partition_Access.c b/components/mesh_ota/Mesh_OTA_Partition_Access.c index 8a6e63f..ea582e4 100644 --- a/components/mesh_ota/Mesh_OTA_Partition_Access.c +++ b/components/mesh_ota/Mesh_OTA_Partition_Access.c @@ -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 diff --git a/components/mesh_ota/Mesh_OTA_Util.c b/components/mesh_ota/Mesh_OTA_Util.c index 712329f..2e3720f 100644 --- a/components/mesh_ota/Mesh_OTA_Util.c +++ b/components/mesh_ota/Mesh_OTA_Util.c @@ -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); + } } } @@ -328,7 +356,7 @@ void vMeshOtaUtilClearOtaMessageQueue(const mesh_addr_t* const cpcMeshNodeAddr) void vMeshOtaUtilClearNeighboursQueue(const mesh_addr_t* const cpcMeshNodeAddr) { mesh_addr_t sNode; //packet for sending and receiving - for (uint32_t u32Index = 0; (u32Index < QUEUE_NODES_SIZE); u32Index++) //loop through all node queue + for (uint32_t u32Index = 0; (u32Index < QUEUE_NODES_SIZE); u32Index++) //loop through all node queue { if (xQueueReceive(queueNodes, &sNode, 0) == pdTRUE) { @@ -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 diff --git a/components/mesh_ota/include/Mesh_OTA_Util.h b/components/mesh_ota/include/Mesh_OTA_Util.h index 68365f0..68c9dfd 100644 --- a/components/mesh_ota/include/Mesh_OTA_Util.h +++ b/components/mesh_ota/include/Mesh_OTA_Util.h @@ -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); diff --git a/main/Blinky_LED.c b/main/Blinky_LED.c index d3e5102..7565415 100644 --- a/main/Blinky_LED.c +++ b/main/Blinky_LED.c @@ -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; diff --git a/main/Blinky_LED.h b/main/Blinky_LED.h index 909d5d4..dbdc564 100644 --- a/main/Blinky_LED.h +++ b/main/Blinky_LED.h @@ -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< Date: Wed, 27 Jan 2021 11:43:30 +0100 Subject: [PATCH 2/4] fix in MAC equality check fn --- components/mesh_ota/Mesh_Network.c | 5 +- components/mesh_ota/test/test_mesh_ota.c | 78 ++++++++++++++++++++++-- 2 files changed, 76 insertions(+), 7 deletions(-) diff --git a/components/mesh_ota/Mesh_Network.c b/components/mesh_ota/Mesh_Network.c index ffe406e..adeb4b9 100644 --- a/components/mesh_ota/Mesh_Network.c +++ b/components/mesh_ota/Mesh_Network.c @@ -320,13 +320,13 @@ bool bMeshNetworkCheckMacEquality(const uint8_t* const cpcu8aMAC, const uint8_t* bool bRet = true; uint8_t index = 0; - while ((index < 6) && (bRet == true)) + while ((index < 10) && (bRet == true)) { if(cpcu8aMAC[index] != cpcu8bMAC[index]) { bRet = false; } - +/* if(index == 5) { //last byte of mac @@ -335,6 +335,7 @@ bool bMeshNetworkCheckMacEquality(const uint8_t* const cpcu8aMAC, const uint8_t* bRet = true; //last byte differs 1 ore less } } + */ index++; } return bRet; diff --git a/components/mesh_ota/test/test_mesh_ota.c b/components/mesh_ota/test/test_mesh_ota.c index d14d66f..f7d0372 100644 --- a/components/mesh_ota/test/test_mesh_ota.c +++ b/components/mesh_ota/test/test_mesh_ota.c @@ -3,6 +3,7 @@ #include "Mesh_OTA_Util.h" #include "test_image_hex.h" +#include "Mesh_Network.h" // ### ### ### distinguish newer image version ### ### ### @@ -206,11 +207,78 @@ TEST_CASE("extract version 999.99.999", "[extract image version number]") } - - - - - +TEST_CASE("same MACs", "[check MAC equality]") +{ + unsigned char cMAC_A[] = "012345678901"; + unsigned char cMAC_B[] = "012345678901"; + + TEST_ASSERT_TRUE( bMeshNetworkCheckMacEquality(cMAC_A,cMAC_B) ); +} + +TEST_CASE("different MACs", "[check MAC equality]") +{ + unsigned char cMAC_A[] = "012345678901"; + unsigned char cMAC_B[] = "087464874718"; + + TEST_ASSERT_FALSE( bMeshNetworkCheckMacEquality(cMAC_A,cMAC_B) ); +} + +TEST_CASE("same MACs last A_byte+1", "[check MAC equality]") +{ + unsigned char cMAC_A[] = "012345678902"; + unsigned char cMAC_B[] = "012345678901"; + + TEST_ASSERT_TRUE( bMeshNetworkCheckMacEquality(cMAC_A,cMAC_B) ); +} + +TEST_CASE("same MACs last B_byte+1", "[check MAC equality]") +{ + unsigned char cMAC_A[] = "012345678901"; + unsigned char cMAC_B[] = "012345678902"; + + TEST_ASSERT_TRUE( bMeshNetworkCheckMacEquality(cMAC_A,cMAC_B) ); +} + +TEST_CASE("same MACs last B_byte+2", "[check MAC equality]") +{ + unsigned char cMAC_A[] = "012345678901"; + unsigned char cMAC_B[] = "012345678903"; + + TEST_ASSERT_TRUE( bMeshNetworkCheckMacEquality(cMAC_A,cMAC_B) ); +} + +TEST_CASE("different MACs last B_byte+2", "[check MAC equality]") +{ + unsigned char cMAC_A[] = "012344678901"; + unsigned char cMAC_B[] = "012345678903"; + + TEST_ASSERT_FALSE( bMeshNetworkCheckMacEquality(cMAC_A,cMAC_B) ); +} + + +TEST_CASE("same Node0", "[check MAC equality]") +{ + unsigned char cMAC_A[] = "ac67b27162b0"; + unsigned char cMAC_B[] = "ac67b27162b0"; + + TEST_ASSERT_TRUE( bMeshNetworkCheckMacEquality(cMAC_A,cMAC_B) ); +} + +TEST_CASE("same Node0 first MAC+1", "[check MAC equality]") +{ + unsigned char cMAC_A[] = "ac67b27162b1"; + unsigned char cMAC_B[] = "ac67b27162b0"; + + TEST_ASSERT_TRUE( bMeshNetworkCheckMacEquality(cMAC_A,cMAC_B) ); +} + +TEST_CASE("same Node0 second MAC+1", "[check MAC equality]") +{ + unsigned char cMAC_A[] = "ac67b27162b0"; + unsigned char cMAC_B[] = "ac67b27162b1"; + + TEST_ASSERT_TRUE( bMeshNetworkCheckMacEquality(cMAC_A,cMAC_B) ); +} From 8e614e76c736de9755e9499ea47ba5ca4c60c605 Mon Sep 17 00:00:00 2001 From: localhorst Date: Wed, 27 Jan 2021 14:31:06 +0100 Subject: [PATCH 3/4] fixed uninitialized node addr that causes bug in upstream ota --- components/mesh_ota/Mesh_Network.c | 39 +++++++--- components/mesh_ota/Mesh_OTA.c | 94 +++++++++++++++--------- components/mesh_ota/Mesh_OTA_Util.c | 12 ++- components/mesh_ota/include/Mesh_OTA.h | 2 +- components/mesh_ota/test/test_mesh_ota.c | 9 --- sdkconfig | 2 +- 6 files changed, 98 insertions(+), 60 deletions(-) diff --git a/components/mesh_ota/Mesh_Network.c b/components/mesh_ota/Mesh_Network.c index adeb4b9..baa0d1b 100644 --- a/components/mesh_ota/Mesh_Network.c +++ b/components/mesh_ota/Mesh_Network.c @@ -320,24 +320,37 @@ bool bMeshNetworkCheckMacEquality(const uint8_t* const cpcu8aMAC, const uint8_t* bool bRet = true; uint8_t index = 0; - while ((index < 10) && (bRet == true)) + while ((index < 5) && (bRet == true)) { + ESP_LOGI(LOG_TAG, "MACequal: check %x and %x",cpcu8aMAC[index], cpcu8bMAC[index] ); if(cpcu8aMAC[index] != cpcu8bMAC[index]) { bRet = false; + ESP_LOGI(LOG_TAG, "MACequal: differ %x and %x",cpcu8aMAC[index], cpcu8bMAC[index] ); } -/* - if(index == 5) - { - //last byte of mac - if(abs((cpcu8aMAC[index] - cpcu8bMAC[index])) <= 1) - { - bRet = true; //last byte differs 1 ore less - } - } - */ + /* + if(index == 5) + { + //last byte of mac + if(abs((cpcu8aMAC[index] - cpcu8bMAC[index])) <= 1) + { + bRet = true; //last byte differs 1 ore less + } + } + */ index++; } + + if(bRet) + { + ESP_LOGI(LOG_TAG, "MAC same"); + } + else + { + ESP_LOGI(LOG_TAG, "MAC NOT same"); + } + + return bRet; } @@ -393,6 +406,8 @@ esp_err_t errMeshNetworkGetChildren(mesh_addr_t* const cpChildren, uint16_t* con mesh_addr_t route_table[CONFIG_MESH_ROUTE_TABLE_SIZE]; ERROR_CHECK(esp_mesh_get_routing_table((mesh_addr_t *) &route_table, (CONFIG_MESH_ROUTE_TABLE_SIZE * 6), &route_table_size)); + ESP_LOGI(LOG_TAG, "child: own Node: \"0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x\" ", u8ownMAC[0], u8ownMAC[1], u8ownMAC[2], u8ownMAC[3], u8ownMAC[4], u8ownMAC[5]); + if (err == ESP_OK) { for(uint16_t index = 0; index < esp_mesh_get_routing_table_size(); index++) @@ -400,7 +415,7 @@ esp_err_t errMeshNetworkGetChildren(mesh_addr_t* const cpChildren, uint16_t* con if(! (bMeshNetworkCheckMacEquality(u8ownMAC, route_table[index].addr)) ) { //child node - //ESP_LOGI(LOG_TAG, "adding Node: \"0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x\" ", route_table[index].addr[0], route_table[index].addr[1], route_table[index].addr[2], route_table[index].addr[3], route_table[index].addr[4], route_table[index].addr[5]); + ESP_LOGI(LOG_TAG, "CHILDADD Node: \"0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x\" ", route_table[index].addr[0], route_table[index].addr[1], route_table[index].addr[2], route_table[index].addr[3], route_table[index].addr[4], route_table[index].addr[5]); cpChildren[*cpu16ChildrenSize] = route_table[index]; (*cpu16ChildrenSize) = (*cpu16ChildrenSize)+1; } diff --git a/components/mesh_ota/Mesh_OTA.c b/components/mesh_ota/Mesh_OTA.c index 14f5e8d..74f81d5 100644 --- a/components/mesh_ota/Mesh_OTA.c +++ b/components/mesh_ota/Mesh_OTA.c @@ -200,7 +200,7 @@ void vMeshOtaTaskOTAWorker(void *arg) } xSemaphoreGive(bsOTAProcess); //free binary semaphore, this allows other tasks to start the OTA process - ERROR_CHECK(errMeshOtaSlaveEndpoint(&bNewOTAImage)); + ERROR_CHECK(errMeshOtaSlaveEndpoint(&bNewOTAImage, &meshNodeAddr)); } else { @@ -231,6 +231,9 @@ void vMeshOtaTaskOTAWorker(void *arg) //set want reboot ESP_LOGI(LOG_TAG, "Updated successfully via Mesh, set pending reboot"); bWantReboot = true; + + ESP_LOGI(LOG_TAG, "Succ updated from MAC: \"%x:%x:%x:%x:%x:%x\" ", meshNodeAddr.addr[0], meshNodeAddr.addr[1], meshNodeAddr.addr[2], meshNodeAddr.addr[3], meshNodeAddr.addr[4], meshNodeAddr.addr[5]); + vMeshOtaUtilAddAllNeighboursToQueue(&meshNodeAddr); //add all existing neighbours to queue } vTaskDelay( (1000) / portTICK_PERIOD_MS); @@ -248,7 +251,7 @@ void vMeshOtaTaskOTAWorker(void *arg) * Answers the OTA_Version_Request with OTA_Version_Response * calls errMeshOtaPartitionAccessMeshReceive OR errMeshOtaPartitionAccessMeshTransmit based on version number */ -esp_err_t errMeshOtaSlaveEndpoint(bool* const cpbNewOTAImage) +esp_err_t errMeshOtaSlaveEndpoint(bool* const cpbNewOTAImage, mesh_addr_t* const cpcMeshNodeAddr) { esp_err_t err = ESP_OK; MESH_PACKET_t sOTAMessage; @@ -270,6 +273,8 @@ esp_err_t errMeshOtaSlaveEndpoint(bool* const cpbNewOTAImage) { xSemaphoreTake(bsOTAProcess, portMAX_DELAY); //wait for binary semaphore that allows to start the OTA process + memcpy(cpcMeshNodeAddr, &sOTAMessage.meshSenderAddr, sizeof(mesh_addr_t)); + cpBootPartition = esp_ota_get_boot_partition(); //get boot partition (that will booted after reset), not the running partition ERROR_CHECK(esp_ota_get_partition_description(cpBootPartition, &bootPartitionDesc)); //get metadata of partition @@ -317,6 +322,7 @@ esp_err_t errMeshOtaMasterEndpoint(bool* const cpbNewOTAImage, const mesh_addr_t esp_app_desc_t bootPartitionDesc; //Metadata from boot partition bool bNodeIsConnected = false; bool bNodeIsResponding = false; + bool bSameVersion = false; *cpbNewOTAImage = false; //set default false @@ -326,50 +332,69 @@ esp_err_t errMeshOtaMasterEndpoint(bool* const cpbNewOTAImage, const mesh_addr_t xSemaphoreTake(bsOTAProcess, portMAX_DELAY); //wait for binary semaphore that allows to start the OTA process ERROR_CHECK(errMeshOtaUtilSendOtaVersionRequest(cpcMeshNodeAddr)); //send OTA_VERSION_REQUEST with local version in payload + ESP_LOGI(LOG_TAG, "MASTER: sent Request to %x", cpcMeshNodeAddr->addr[5]); - for (uint32_t u32Index = 0; u32Index < QUEUE_MESSAGE_OTA_SIZE; u32Index++) //loop through all OTA messages + for (uint32_t u32Index = 0; ((u32Index < QUEUE_MESSAGE_OTA_SIZE) && (bSameVersion == false)); u32Index++) //loop through all OTA messages { - if(uxQueueSpacesAvailable(queueMessageOTA) < QUEUE_MESSAGE_OTA_SIZE) + //if(uxQueueSpacesAvailable(queueMessageOTA) < QUEUE_MESSAGE_OTA_SIZE) + // { + //queue not empty + if (xQueueReceive(queueMessageOTA, &sOTAMessage, ((3000) / portTICK_PERIOD_MS)) != pdTRUE) { - //queue not empty - if (xQueueReceive(queueMessageOTA, &sOTAMessage, ((3000) / portTICK_PERIOD_MS)) != pdTRUE) + ESP_LOGE(LOG_TAG, "MASTER: Unable to receive OTA Messages from queue"); + err = ESP_FAIL; + } + else + { + ESP_LOGI(LOG_TAG, "MASTER: rec message: %i", sOTAMessage.type); + } + + if((err == ESP_OK) && (sOTAMessage.type == OTA_Version_Response) && (bMeshNetworkCheckMacEquality(sOTAMessage.meshSenderAddr.addr, cpcMeshNodeAddr->addr))) //if OTA_Version_Request + { + bSameVersion = true; + bNodeIsResponding = true; + cpBootPartition = esp_ota_get_boot_partition(); //get boot partition (that will booted after reset), not the running partition + ERROR_CHECK(esp_ota_get_partition_description(cpBootPartition, &bootPartitionDesc)); //get metadata of partition + + if((bMeshOtaUtilNewerVersion((bootPartitionDesc).version, (char*) sOTAMessage.au8Payload)) && (err == ESP_OK)) //compare local and remote version { - ESP_LOGE(LOG_TAG, "MASTER: Unable to receive OTA Messages from queue"); - err = ESP_FAIL; + //remote newer as local + bSameVersion = false; + 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)); + u32Index = QUEUE_MESSAGE_OTA_SIZE; } - if((err == ESP_OK) && (sOTAMessage.type == OTA_Version_Response) && (bMeshNetworkCheckMacEquality(sOTAMessage.meshSenderAddr.addr, cpcMeshNodeAddr->addr))) //if OTA_Version_Request + if((bMeshOtaUtilNewerVersion((char*) sOTAMessage.au8Payload, (bootPartitionDesc).version)) && (err == ESP_OK)) //compare remote and local version { - bNodeIsResponding = true; - cpBootPartition = esp_ota_get_boot_partition(); //get boot partition (that will booted after reset), not the running partition - ERROR_CHECK(esp_ota_get_partition_description(cpBootPartition, &bootPartitionDesc)); //get metadata of partition - - if((bMeshOtaUtilNewerVersion((bootPartitionDesc).version, (char*) sOTAMessage.au8Payload)) && (err == ESP_OK)) //compare local and remote version - { - //remote newer as local - 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)); - } - - if((bMeshOtaUtilNewerVersion((char*) sOTAMessage.au8Payload, (bootPartitionDesc).version)) && (err == ESP_OK)) //compare remote and local version - { - //local newer as remote - 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)); - } + //local newer as remote + bSameVersion = false; + 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)); + u32Index = QUEUE_MESSAGE_OTA_SIZE; } + + + if(bSameVersion == true) + { + ESP_LOGI(LOG_TAG, "MASTER: same version --> NO OTA update"); + } + + + /* } else if (err == ESP_OK) - { - //received from wrong node or type --> back to queue - vMeshOtaUtilAddOtaMessageToQueue(&sOTAMessage); - } + { + //received from wrong node or type --> back to queue + vMeshOtaUtilAddOtaMessageToQueue(&sOTAMessage); + } + */ } else { // OTA Message queue is empty --> wait some time - ESP_LOGD(LOG_TAG, "OTA-Master: OTA Message queue is empty --> wait some time"); + ESP_LOGI(LOG_TAG, "OTA-Master: OTA Message queue is empty --> wait some time"); vTaskDelay( (1000/QUEUE_MESSAGE_OTA_SIZE) / portTICK_PERIOD_MS); } }//end loop @@ -382,5 +407,8 @@ esp_err_t errMeshOtaMasterEndpoint(bool* const cpbNewOTAImage, const mesh_addr_t ESP_LOGI(LOG_TAG, "OTA-Master: connected and NOT responding --> add node back to queue "); vMeshOtaUtilAddNodeToPossibleUpdatableQueue(cpcMeshNodeAddr->addr); } + + + ESP_LOGI(LOG_TAG, "OTA-Master: return with %i ", err); return err; } diff --git a/components/mesh_ota/Mesh_OTA_Util.c b/components/mesh_ota/Mesh_OTA_Util.c index 2e3720f..8453b49 100644 --- a/components/mesh_ota/Mesh_OTA_Util.c +++ b/components/mesh_ota/Mesh_OTA_Util.c @@ -287,11 +287,13 @@ void vMeshOtaUtilAddAllNeighboursToQueue(const mesh_addr_t* const cpcMeshNodeAdd } else { + ESP_LOGI(LOG_TAG, "AddAllNodes: parent: %x - %x", addrParent.addr[5], cpcMeshNodeAddr->addr[5]); vMeshOtaUtilAddNodeToPossibleUpdatableQueue(addrParent.addr); } } else { + ESP_LOGI(LOG_TAG, "AddAllNodes: NULL parent"); vMeshOtaUtilAddNodeToPossibleUpdatableQueue(addrParent.addr); } @@ -311,11 +313,13 @@ void vMeshOtaUtilAddAllNeighboursToQueue(const mesh_addr_t* const cpcMeshNodeAdd } else { + ESP_LOGI(LOG_TAG, "AddAllNodes: Child: %x", childrenAddr[u16Index].addr[5]); vMeshOtaUtilAddNodeToPossibleUpdatableQueue(childrenAddr[u16Index].addr); } } else { + ESP_LOGI(LOG_TAG, "AddAllNodes: NULL Child: %x", childrenAddr[u16Index].addr[5]); vMeshOtaUtilAddNodeToPossibleUpdatableQueue(childrenAddr[u16Index].addr); } } @@ -366,7 +370,7 @@ void vMeshOtaUtilClearNeighboursQueue(const mesh_addr_t* const cpcMeshNodeAddr) } else { - ESP_LOGI(LOG_TAG, "//node is NOT cpcMeshNodeAddr: %i --> keep it in queue", sNode.addr[5]); + ESP_LOGI(LOG_TAG, "//node is NOT cpcMeshNodeAddr: %x --> keep it in queue", sNode.addr[5]); vMeshOtaUtilAddNodeToPossibleUpdatableQueue(sNode.addr); } @@ -422,14 +426,14 @@ void vMeshOtaUtilAddOtaMessageToQueue(const MESH_PACKET_t* const cpcuMeshPacket) switch (cpcuMeshPacket->type) { case OTA_Abort: - ESP_LOGD(LOG_TAG, "added ota message to queue: OTA_Abort from 0x%x", cpcuMeshPacket->meshSenderAddr.addr[5]); + ESP_LOGI(LOG_TAG, "added ota message to queue: OTA_Abort from 0x%x", cpcuMeshPacket->meshSenderAddr.addr[5]); break; case OTA_Version_Request: - ESP_LOGD(LOG_TAG, "added ota message to queue: OTA_Version_Request from 0x%x", cpcuMeshPacket->meshSenderAddr.addr[5]); + ESP_LOGI(LOG_TAG, "added ota message to queue: OTA_Version_Request from 0x%x", cpcuMeshPacket->meshSenderAddr.addr[5]); break; case OTA_Version_Response: - ESP_LOGD(LOG_TAG, "added ota message to queue: OTA_Version Response from 0x%x", cpcuMeshPacket->meshSenderAddr.addr[5]); + ESP_LOGI(LOG_TAG, "added ota message to queue: OTA_Version Response from 0x%x", cpcuMeshPacket->meshSenderAddr.addr[5]); break; default: break; diff --git a/components/mesh_ota/include/Mesh_OTA.h b/components/mesh_ota/include/Mesh_OTA.h index d28421f..53b8b90 100644 --- a/components/mesh_ota/include/Mesh_OTA.h +++ b/components/mesh_ota/include/Mesh_OTA.h @@ -43,7 +43,7 @@ void vMeshOtaTaskServerWorker(void *arg); void vMeshOtaTaskOTAWorker(void *arg); //OTA process endpoints -esp_err_t errMeshOtaSlaveEndpoint(bool* const cpbNewOTAImage); +esp_err_t errMeshOtaSlaveEndpoint(bool* const cpbNewOTAImage, mesh_addr_t* const cpcMeshNodeAddr); esp_err_t errMeshOtaMasterEndpoint(bool* const cpbNewOTAImage, const mesh_addr_t* const cpcMeshNodeAddr); #endif /* H_MESH_OTA */ diff --git a/components/mesh_ota/test/test_mesh_ota.c b/components/mesh_ota/test/test_mesh_ota.c index f7d0372..6cc4198 100644 --- a/components/mesh_ota/test/test_mesh_ota.c +++ b/components/mesh_ota/test/test_mesh_ota.c @@ -247,15 +247,6 @@ TEST_CASE("same MACs last B_byte+2", "[check MAC equality]") TEST_ASSERT_TRUE( bMeshNetworkCheckMacEquality(cMAC_A,cMAC_B) ); } -TEST_CASE("different MACs last B_byte+2", "[check MAC equality]") -{ - unsigned char cMAC_A[] = "012344678901"; - unsigned char cMAC_B[] = "012345678903"; - - TEST_ASSERT_FALSE( bMeshNetworkCheckMacEquality(cMAC_A,cMAC_B) ); -} - - TEST_CASE("same Node0", "[check MAC equality]") { unsigned char cMAC_A[] = "ac67b27162b0"; diff --git a/sdkconfig b/sdkconfig index a1c4952..11cd837 100644 --- a/sdkconfig +++ b/sdkconfig @@ -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.40" +CONFIG_APP_PROJECT_VER="0.0.46" CONFIG_APP_RETRIEVE_LEN_ELF_SHA=16 # end of Application manager From b9e0769843935d9e090fa53cd47e3b1cd5f40e1d Mon Sep 17 00:00:00 2001 From: localhorst Date: Wed, 27 Jan 2021 16:47:25 +0100 Subject: [PATCH 4/4] cleanup debug out --- components/mesh_ota/Mesh_Network.c | 28 +----------- components/mesh_ota/Mesh_OTA.c | 44 ++++--------------- .../mesh_ota/Mesh_OTA_Partition_Access.c | 16 +------ components/mesh_ota/Mesh_OTA_Util.c | 24 ++++------ main/Blinky_LED.h | 1 - sdkconfig | 2 +- 6 files changed, 19 insertions(+), 96 deletions(-) diff --git a/components/mesh_ota/Mesh_Network.c b/components/mesh_ota/Mesh_Network.c index baa0d1b..c2507c8 100644 --- a/components/mesh_ota/Mesh_Network.c +++ b/components/mesh_ota/Mesh_Network.c @@ -308,7 +308,7 @@ bool bMeshNetworkIsNodeNeighbour(const mesh_addr_t* const cpcNode) /** * @fn bool bMeshNetworkCheckMacEquality(const uint8_t* const cpcu8aMAC, const uint8_t* const cpcu8bMAC) -* @brief returns true if MAC address is equal +* @brief returns true if MAC address is equal, compares only the first 5 bytes, the last is node specific * @param cpcu8aMAC first MAC * @param cpcu8bMAC second MAC * @return boolean @@ -322,35 +322,12 @@ bool bMeshNetworkCheckMacEquality(const uint8_t* const cpcu8aMAC, const uint8_t* while ((index < 5) && (bRet == true)) { - ESP_LOGI(LOG_TAG, "MACequal: check %x and %x",cpcu8aMAC[index], cpcu8bMAC[index] ); if(cpcu8aMAC[index] != cpcu8bMAC[index]) { bRet = false; - ESP_LOGI(LOG_TAG, "MACequal: differ %x and %x",cpcu8aMAC[index], cpcu8bMAC[index] ); } - /* - if(index == 5) - { - //last byte of mac - if(abs((cpcu8aMAC[index] - cpcu8bMAC[index])) <= 1) - { - bRet = true; //last byte differs 1 ore less - } - } - */ index++; } - - if(bRet) - { - ESP_LOGI(LOG_TAG, "MAC same"); - } - else - { - ESP_LOGI(LOG_TAG, "MAC NOT same"); - } - - return bRet; } @@ -406,8 +383,6 @@ esp_err_t errMeshNetworkGetChildren(mesh_addr_t* const cpChildren, uint16_t* con mesh_addr_t route_table[CONFIG_MESH_ROUTE_TABLE_SIZE]; ERROR_CHECK(esp_mesh_get_routing_table((mesh_addr_t *) &route_table, (CONFIG_MESH_ROUTE_TABLE_SIZE * 6), &route_table_size)); - ESP_LOGI(LOG_TAG, "child: own Node: \"0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x\" ", u8ownMAC[0], u8ownMAC[1], u8ownMAC[2], u8ownMAC[3], u8ownMAC[4], u8ownMAC[5]); - if (err == ESP_OK) { for(uint16_t index = 0; index < esp_mesh_get_routing_table_size(); index++) @@ -415,7 +390,6 @@ esp_err_t errMeshNetworkGetChildren(mesh_addr_t* const cpChildren, uint16_t* con if(! (bMeshNetworkCheckMacEquality(u8ownMAC, route_table[index].addr)) ) { //child node - ESP_LOGI(LOG_TAG, "CHILDADD Node: \"0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x\" ", route_table[index].addr[0], route_table[index].addr[1], route_table[index].addr[2], route_table[index].addr[3], route_table[index].addr[4], route_table[index].addr[5]); cpChildren[*cpu16ChildrenSize] = route_table[index]; (*cpu16ChildrenSize) = (*cpu16ChildrenSize)+1; } diff --git a/components/mesh_ota/Mesh_OTA.c b/components/mesh_ota/Mesh_OTA.c index 74f81d5..8d50d0d 100644 --- a/components/mesh_ota/Mesh_OTA.c +++ b/components/mesh_ota/Mesh_OTA.c @@ -189,7 +189,7 @@ void vMeshOtaTaskOTAWorker(void *arg) if((uxQueueSpacesAvailable(queueNodes) - QUEUE_NODES_SIZE) == 0) { - ESP_LOGI(LOG_TAG, "//nodes queue is empty"); + //nodes queue is empty 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)) @@ -204,15 +204,13 @@ void vMeshOtaTaskOTAWorker(void *arg) } else { - ESP_LOGI(LOG_TAG, "//queue not empty %i", (uxQueueSpacesAvailable(queueNodes) - QUEUE_NODES_SIZE)); + //queue not empty if (xQueueReceive(queueNodes, &meshNodeAddr, ((100) / portTICK_PERIOD_MS)) != pdTRUE) { ESP_LOGE(LOG_TAG, "Unable to receive OTA Messages from Queue"); err = ESP_FAIL; } - ESP_LOGI(LOG_TAG, "//handle node %x", meshNodeAddr.addr[5]); - ERROR_CHECK(errMeshOtaMasterEndpoint(&bNewOTAImage, &meshNodeAddr)); if (err != ESP_OK) @@ -232,8 +230,6 @@ void vMeshOtaTaskOTAWorker(void *arg) ESP_LOGI(LOG_TAG, "Updated successfully via Mesh, set pending reboot"); bWantReboot = true; - ESP_LOGI(LOG_TAG, "Succ updated from MAC: \"%x:%x:%x:%x:%x:%x\" ", meshNodeAddr.addr[0], meshNodeAddr.addr[1], meshNodeAddr.addr[2], meshNodeAddr.addr[3], meshNodeAddr.addr[4], meshNodeAddr.addr[5]); - vMeshOtaUtilAddAllNeighboursToQueue(&meshNodeAddr); //add all existing neighbours to queue } vTaskDelay( (1000) / portTICK_PERIOD_MS); @@ -244,6 +240,7 @@ void vMeshOtaTaskOTAWorker(void *arg) * @fn esp_err_t errMeshOtaSlaveEndpoint(bool* const cpbNewOTAImage) * @brief Endpoint for OTA process that is called from remote node * @param cpbNewOTAImage pointer to boolean to signal if a new image was successfully received +* @param cpcMeshNodeAddr pointer to mesh node that transmitted the update * @return ESP32 error code * @author Hendrik Schutter * @date 21.01.2021 @@ -265,7 +262,6 @@ esp_err_t errMeshOtaSlaveEndpoint(bool* const cpbNewOTAImage, mesh_addr_t* const //queue not empty if (xQueueReceive(queueMessageOTA, &sOTAMessage, ((100) / portTICK_PERIOD_MS)) != pdTRUE) { - ESP_LOGE(LOG_TAG, "SLAVE: Unable to receive OTA Messages from Queue"); err = ESP_FAIL; } @@ -284,7 +280,7 @@ esp_err_t errMeshOtaSlaveEndpoint(bool* const cpbNewOTAImage, mesh_addr_t* const if((bMeshOtaUtilNewerVersion((bootPartitionDesc).version, (char*) sOTAMessage.au8Payload)) && (err == ESP_OK)) //compare local and remote version { //remote newer as local - 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]); + 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]); // --> this version older --> start OTA_Rx --> set cpbNewOTAImage true ERROR_CHECK(errMeshOtaPartitionAccessMeshReceive(cpbNewOTAImage, &sOTAMessage.meshSenderAddr)); } @@ -292,7 +288,7 @@ esp_err_t errMeshOtaSlaveEndpoint(bool* const cpbNewOTAImage, mesh_addr_t* const if((bMeshOtaUtilNewerVersion((char*) sOTAMessage.au8Payload, (bootPartitionDesc).version)) && (err == ESP_OK)) //compare remote and local version { //local newer as remote - 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]); + 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]); // --> this version newer --> start OTA_Tx ERROR_CHECK(errMeshOtaPartitionAccessMeshTransmit(&sOTAMessage.meshSenderAddr)); } @@ -332,7 +328,6 @@ esp_err_t errMeshOtaMasterEndpoint(bool* const cpbNewOTAImage, const mesh_addr_t xSemaphoreTake(bsOTAProcess, portMAX_DELAY); //wait for binary semaphore that allows to start the OTA process ERROR_CHECK(errMeshOtaUtilSendOtaVersionRequest(cpcMeshNodeAddr)); //send OTA_VERSION_REQUEST with local version in payload - ESP_LOGI(LOG_TAG, "MASTER: sent Request to %x", cpcMeshNodeAddr->addr[5]); for (uint32_t u32Index = 0; ((u32Index < QUEUE_MESSAGE_OTA_SIZE) && (bSameVersion == false)); u32Index++) //loop through all OTA messages { @@ -341,13 +336,9 @@ 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, "MASTER: Unable to receive OTA Messages from queue"); + ESP_LOGE(LOG_TAG, "Unable to receive OTA Messages from queue"); err = ESP_FAIL; } - else - { - ESP_LOGI(LOG_TAG, "MASTER: rec message: %i", sOTAMessage.type); - } if((err == ESP_OK) && (sOTAMessage.type == OTA_Version_Response) && (bMeshNetworkCheckMacEquality(sOTAMessage.meshSenderAddr.addr, cpcMeshNodeAddr->addr))) //if OTA_Version_Request { @@ -360,7 +351,7 @@ esp_err_t errMeshOtaMasterEndpoint(bool* const cpbNewOTAImage, const mesh_addr_t { //remote newer as local bSameVersion = false; - 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]); + 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]); // --> this version older --> start OTA_Rx --> set cpbNewOTAImage true ERROR_CHECK(errMeshOtaPartitionAccessMeshReceive(cpbNewOTAImage, &sOTAMessage.meshSenderAddr)); u32Index = QUEUE_MESSAGE_OTA_SIZE; @@ -370,31 +361,15 @@ esp_err_t errMeshOtaMasterEndpoint(bool* const cpbNewOTAImage, const mesh_addr_t { //local newer as remote bSameVersion = false; - 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]); + 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]); // --> this version newer --> start OTA_Tx ERROR_CHECK(errMeshOtaPartitionAccessMeshTransmit(&sOTAMessage.meshSenderAddr)); u32Index = QUEUE_MESSAGE_OTA_SIZE; } - - - if(bSameVersion == true) - { - ESP_LOGI(LOG_TAG, "MASTER: same version --> NO OTA update"); - } - - - /* } - else if (err == ESP_OK) - { - //received from wrong node or type --> back to queue - vMeshOtaUtilAddOtaMessageToQueue(&sOTAMessage); - } - */ } else { // OTA Message queue is empty --> wait some time - ESP_LOGI(LOG_TAG, "OTA-Master: OTA Message queue is empty --> wait some time"); vTaskDelay( (1000/QUEUE_MESSAGE_OTA_SIZE) / portTICK_PERIOD_MS); } }//end loop @@ -407,8 +382,5 @@ esp_err_t errMeshOtaMasterEndpoint(bool* const cpbNewOTAImage, const mesh_addr_t ESP_LOGI(LOG_TAG, "OTA-Master: connected and NOT responding --> add node back to queue "); vMeshOtaUtilAddNodeToPossibleUpdatableQueue(cpcMeshNodeAddr->addr); } - - - ESP_LOGI(LOG_TAG, "OTA-Master: return with %i ", err); return err; } diff --git a/components/mesh_ota/Mesh_OTA_Partition_Access.c b/components/mesh_ota/Mesh_OTA_Partition_Access.c index ea582e4..896d378 100644 --- a/components/mesh_ota/Mesh_OTA_Partition_Access.c +++ b/components/mesh_ota/Mesh_OTA_Partition_Access.c @@ -155,10 +155,7 @@ esp_err_t errMeshOtaPartitionAccessMeshTransmit(const mesh_addr_t* const cpcMesh 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 @@ -199,12 +196,6 @@ esp_err_t errMeshOtaPartitionAccessMeshTransmit(const mesh_addr_t* const cpcMesh break; } } - else if (err == ESP_OK) - { - ESP_LOGI(LOG_TAG, "OTA-TX: //received from wrong node --> back to queue"); - //vMeshOtaUtilAddOtaMessageToQueue(&sMeshPacket); - //vTaskDelay( (1000) / portTICK_PERIOD_MS); - } }//end OTA message loop if(bNodeIsResponding == false) @@ -255,8 +246,6 @@ esp_err_t errMeshOtaPartitionAccessMeshReceive(bool* const cpbNewOTAImage, const // loop through all OTA messages or until abort is called for (uint32_t u32Index = 0; ((u32Index < QUEUE_MESSAGE_OTA_SIZE) && (bAbort == false)); u32Index++) //loop through all OTA messages { - //if(uxQueueSpacesAvailable(queueMessageOTA) < QUEUE_MESSAGE_OTA_SIZE) - // { //queue not empty if (xQueueReceive(queueMessageOTA, &sMeshPacket, ((OTA_MESH_TIMEOUT) / portTICK_PERIOD_MS)) != pdTRUE) { @@ -271,10 +260,8 @@ 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 @@ -317,7 +304,6 @@ 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 diff --git a/components/mesh_ota/Mesh_OTA_Util.c b/components/mesh_ota/Mesh_OTA_Util.c index 8453b49..a6a56de 100644 --- a/components/mesh_ota/Mesh_OTA_Util.c +++ b/components/mesh_ota/Mesh_OTA_Util.c @@ -262,8 +262,8 @@ void vMeshOtaUtilPrintOtaProgress(const uint32_t* const cpcu32TotalImageSize, co /** * @fn void vMeshOtaUtilAddAllNeighboursToQueue(void) -* @brief add all neigbhours (children and parent) to queue -* @param void +* @brief add all neigbhours (children and parent) to queue, except node used in parameter +* @param const mesh_addr_t* const cpcMeshNodeAddr * @return void * @author Hendrik Schutter * @date 21.01.2021 @@ -287,13 +287,11 @@ void vMeshOtaUtilAddAllNeighboursToQueue(const mesh_addr_t* const cpcMeshNodeAdd } else { - ESP_LOGI(LOG_TAG, "AddAllNodes: parent: %x - %x", addrParent.addr[5], cpcMeshNodeAddr->addr[5]); vMeshOtaUtilAddNodeToPossibleUpdatableQueue(addrParent.addr); } } else { - ESP_LOGI(LOG_TAG, "AddAllNodes: NULL parent"); vMeshOtaUtilAddNodeToPossibleUpdatableQueue(addrParent.addr); } @@ -313,13 +311,11 @@ void vMeshOtaUtilAddAllNeighboursToQueue(const mesh_addr_t* const cpcMeshNodeAdd } else { - ESP_LOGI(LOG_TAG, "AddAllNodes: Child: %x", childrenAddr[u16Index].addr[5]); vMeshOtaUtilAddNodeToPossibleUpdatableQueue(childrenAddr[u16Index].addr); } } else { - ESP_LOGI(LOG_TAG, "AddAllNodes: NULL Child: %x", childrenAddr[u16Index].addr[5]); vMeshOtaUtilAddNodeToPossibleUpdatableQueue(childrenAddr[u16Index].addr); } } @@ -366,19 +362,15 @@ void vMeshOtaUtilClearNeighboursQueue(const mesh_addr_t* const cpcMeshNodeAddr) { if((bMeshNetworkCheckMacEquality(sNode.addr, cpcMeshNodeAddr->addr))) { - ESP_LOGI(LOG_TAG, "REMOVE_NODE: remove node %x", sNode.addr[5]); + //same node --> don't add again } else { - ESP_LOGI(LOG_TAG, "//node is NOT cpcMeshNodeAddr: %x --> keep it in queue", sNode.addr[5]); + //node is NOT cpcMeshNodeAddr --> keep it in queue vMeshOtaUtilAddNodeToPossibleUpdatableQueue(sNode.addr); } } - else - { - ESP_LOGI(LOG_TAG, "REMOVE_NODE: queue leer"); - } }//end nodes } @@ -402,7 +394,7 @@ void vMeshOtaUtilAddNodeToPossibleUpdatableQueue(const uint8_t* const cpcu8MAC) } else { - ESP_LOGI(LOG_TAG, "added node \"%x:%x:%x:%x:%x:%x\" to possible updatable queue", addrNode.addr[0], addrNode.addr[1], addrNode.addr[2], addrNode.addr[3], addrNode.addr[4], addrNode.addr[5]); + ESP_LOGD(LOG_TAG, "added node \"%x:%x:%x:%x:%x:%x\" to possible updatable queue", addrNode.addr[0], addrNode.addr[1], addrNode.addr[2], addrNode.addr[3], addrNode.addr[4], addrNode.addr[5]); } } @@ -426,14 +418,14 @@ void vMeshOtaUtilAddOtaMessageToQueue(const MESH_PACKET_t* const cpcuMeshPacket) switch (cpcuMeshPacket->type) { case OTA_Abort: - ESP_LOGI(LOG_TAG, "added ota message to queue: OTA_Abort from 0x%x", cpcuMeshPacket->meshSenderAddr.addr[5]); + ESP_LOGD(LOG_TAG, "added ota message to queue: OTA_Abort from 0x%x", cpcuMeshPacket->meshSenderAddr.addr[5]); break; case OTA_Version_Request: - ESP_LOGI(LOG_TAG, "added ota message to queue: OTA_Version_Request from 0x%x", cpcuMeshPacket->meshSenderAddr.addr[5]); + ESP_LOGD(LOG_TAG, "added ota message to queue: OTA_Version_Request from 0x%x", cpcuMeshPacket->meshSenderAddr.addr[5]); break; case OTA_Version_Response: - ESP_LOGI(LOG_TAG, "added ota message to queue: OTA_Version Response from 0x%x", cpcuMeshPacket->meshSenderAddr.addr[5]); + ESP_LOGD(LOG_TAG, "added ota message to queue: OTA_Version Response from 0x%x", cpcuMeshPacket->meshSenderAddr.addr[5]); break; default: break; diff --git a/main/Blinky_LED.h b/main/Blinky_LED.h index dbdc564..77d11ce 100644 --- a/main/Blinky_LED.h +++ b/main/Blinky_LED.h @@ -26,7 +26,6 @@ #define GPIO_LED_BLUE 2 //GPIO2 (internal blue LED in DevKit V1.0) #define GPIO_LED_GREEN 13 //GPIO13 - #define GPIO_INPUT_PIN_SEL (1ULL<