added control for http_ota task
This commit is contained in:
parent
62d16a437a
commit
c6829f0483
|
@ -1,5 +1,153 @@
|
||||||
#include "Mesh_OTA.h"
|
#include "Mesh_OTA.h"
|
||||||
|
|
||||||
|
|
||||||
|
static const char *LOG_TAG = "mesh_ota";
|
||||||
|
|
||||||
|
xQueueHandle queueNodes; //nodes that should be checked for ota update (contains children and parent)
|
||||||
|
xQueueHandle queueMessageOTA; //mesh ota controll messages like "OTA_Version_Response" "OTA_ACK"
|
||||||
|
|
||||||
|
SemaphoreHandle_t bsStartStopServerWorker; //binary semaphore
|
||||||
|
|
||||||
|
esp_err_t errMeshOTAInitialize()
|
||||||
|
{
|
||||||
|
esp_err_t err = ESP_OK;
|
||||||
|
BaseType_t xReturned;
|
||||||
|
|
||||||
|
//create queue to store nodes for ota worker task
|
||||||
|
queueNodes = xQueueCreate(QUEUE_NODES_SIZE, sizeof(mesh_addr_t));
|
||||||
|
if (queueNodes == 0) // Queue not created
|
||||||
|
{
|
||||||
|
ESP_LOGE(LOG_TAG, "Unable to create Queue for Nodes");
|
||||||
|
err = ESP_FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(err == ESP_OK)
|
||||||
|
{
|
||||||
|
//create queue to store ota messages
|
||||||
|
queueMessageOTA = xQueueCreate(QUEUE_MESSAGE_OTA_SIZE, sizeof(MESH_PACKET_t));
|
||||||
|
if (queueMessageOTA == 0) // Queue not created
|
||||||
|
{
|
||||||
|
ESP_LOGE(LOG_TAG, "Unable to create Queue for OTA Messages");
|
||||||
|
err = ESP_FAIL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(err == ESP_OK)
|
||||||
|
{
|
||||||
|
bsStartStopServerWorker = xSemaphoreCreateBinary();
|
||||||
|
if( bsStartStopServerWorker == NULL )
|
||||||
|
{
|
||||||
|
ESP_LOGE(LOG_TAG, "Unable to create Mutex to represent state of Server worker");
|
||||||
|
err = ESP_FAIL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ERROR_CHECK(errMeshNetworkSetChildConnectedHandle(vAddNodeToPossibleUpdatableQueue));
|
||||||
|
ERROR_CHECK(errMeshNetworkSetOTAMessageHandleHandle(vAddOTAControllMessageToQueue));
|
||||||
|
ERROR_CHECK(errMeshNetworkSetChangeStateOfServerWorkerHandle(vChangeStateOfServerWorker));
|
||||||
|
|
||||||
|
if(err == ESP_OK)
|
||||||
|
{
|
||||||
|
xReturned = xTaskCreate(vTaskServerWorker, "vTaskServerWorker", 4096, NULL, 5, NULL);
|
||||||
|
if(xReturned != pdPASS)
|
||||||
|
{
|
||||||
|
ESP_LOGE(LOG_TAG, "Unable to create the server worker task");
|
||||||
|
err = ESP_FAIL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void vAddNodeToPossibleUpdatableQueue(uint8_t* pu8Data)
|
||||||
|
{
|
||||||
|
//send payload to node queue
|
||||||
|
mesh_addr_t addrNode;
|
||||||
|
memcpy(&addrNode.addr, (uint8_t *)pu8Data, 6); //copy MAC
|
||||||
|
|
||||||
|
if (xQueueSend(queueNodes, &addrNode, portMAX_DELAY) != pdPASS)
|
||||||
|
{
|
||||||
|
ESP_LOGE(LOG_TAG, "Unable to push node into node queue");
|
||||||
|
}
|
||||||
|
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]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void vAddOTAControllMessageToQueue(MESH_PACKET_t* puMeshPacket)
|
||||||
|
{
|
||||||
|
//send ota packet to packet queue
|
||||||
|
if (xQueueSend(queueMessageOTA, puMeshPacket, portMAX_DELAY) != pdPASS)
|
||||||
|
{
|
||||||
|
ESP_LOGE(LOG_TAG, "Unable to push ota packet into packet queue");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ESP_LOGI(LOG_TAG, "added ota controll message to queue");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void vChangeStateOfServerWorker(bool bState) //allow access via function ptn to networl_handler
|
||||||
|
{
|
||||||
|
static bool bLastState = false;
|
||||||
|
|
||||||
|
if(bState != bLastState) //change only if necessary
|
||||||
|
{
|
||||||
|
ESP_LOGI(LOG_TAG, "server worker change handler");
|
||||||
|
|
||||||
|
if(bState == true)
|
||||||
|
{
|
||||||
|
if (xSemaphoreGive(bsStartStopServerWorker) != pdTRUE)
|
||||||
|
{
|
||||||
|
ESP_LOGE(LOG_TAG, "Unable to give mutex to activate the server worker");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (xSemaphoreTake(bsStartStopServerWorker,( TickType_t ) 10 ) != pdTRUE)
|
||||||
|
{
|
||||||
|
ESP_LOGE(LOG_TAG, "Unable to obtain mutex to deactivate the server worker");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
bLastState = bState;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void vTaskOTAWorker(void *arg)
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void vTaskServerWorker(void *arg)
|
||||||
|
{
|
||||||
|
while(true)
|
||||||
|
{
|
||||||
|
xSemaphoreTake(bsStartStopServerWorker, portMAX_DELAY); //wait for binary semaphore that allows to start the worker
|
||||||
|
xSemaphoreGive(bsStartStopServerWorker); //free binary semaphore, this allows the handler to change is to taken
|
||||||
|
|
||||||
|
if (esp_mesh_is_root()) //check again that this node is the root node
|
||||||
|
{
|
||||||
|
ESP_LOGI(LOG_TAG, "DEMO HTTP request");
|
||||||
|
|
||||||
|
//server get version
|
||||||
|
|
||||||
|
//ota update if newer
|
||||||
|
|
||||||
|
//lock ota mutex
|
||||||
|
|
||||||
|
vTaskDelay( (SERVER_CHECK_INTERVAL*1000) / portTICK_PERIOD_MS); //sleep till next server check
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* 999.999.999
|
* 999.999.999
|
||||||
* Return true if remote version is newer (higher) than local version
|
* Return true if remote version is newer (higher) than local version
|
||||||
|
@ -20,15 +168,15 @@ bool bNewerVersion(const char* pu8Local, const char* pu8Remote)
|
||||||
char* pu8TokenRemote = strtok_r(u8RemoteTmp, ".", &pu8saveptrRemote); //split tokens
|
char* pu8TokenRemote = strtok_r(u8RemoteTmp, ".", &pu8saveptrRemote); //split tokens
|
||||||
|
|
||||||
while( (u8Index <= 2) && (bReturn == false)) //loop through tokens
|
while( (u8Index <= 2) && (bReturn == false)) //loop through tokens
|
||||||
{
|
|
||||||
u8Index++;
|
|
||||||
if(atoi(pu8TokenLocal) < atoi(pu8TokenRemote))
|
|
||||||
{
|
{
|
||||||
bReturn = true; //version number difference --> stop loop
|
u8Index++;
|
||||||
|
if(atoi(pu8TokenLocal) < atoi(pu8TokenRemote))
|
||||||
|
{
|
||||||
|
bReturn = true; //version number difference --> stop loop
|
||||||
|
}
|
||||||
|
pu8TokenLocal = strtok_r(NULL, ".", &pu8saveptrLocal); //split tokens
|
||||||
|
pu8TokenRemote = strtok_r(NULL, ".", &pu8saveptrRemote); //split tokens
|
||||||
}
|
}
|
||||||
pu8TokenLocal = strtok_r(NULL, ".", &pu8saveptrLocal); //split tokens
|
|
||||||
pu8TokenRemote = strtok_r(NULL, ".", &pu8saveptrRemote); //split tokens
|
|
||||||
}
|
|
||||||
return bReturn;
|
return bReturn;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,61 +199,61 @@ esp_err_t errFindImageStart(const char* pu8Data, uint32_t* pu32DataLenght, uint3
|
||||||
*pu32StartOffset = 0U; //reset offset to zero
|
*pu32StartOffset = 0U; //reset offset to zero
|
||||||
|
|
||||||
while((u32DataIndex < *pu32DataLenght) && (bImageStartOffsetFound == false))
|
while((u32DataIndex < *pu32DataLenght) && (bImageStartOffsetFound == false))
|
||||||
{
|
|
||||||
//search for magic byte
|
|
||||||
if(pu8Data[u32DataIndex] == 0xe9)
|
|
||||||
{
|
{
|
||||||
//magic byte found
|
//search for magic byte
|
||||||
while ((u8FirstDotIndex < 3) && (u32FirstDotOffset == 0))
|
if(pu8Data[u32DataIndex] == 0xe9)
|
||||||
{
|
|
||||||
//search first dot in version number
|
|
||||||
if((u32DataIndex+49+u8FirstDotIndex) < *pu32DataLenght)
|
|
||||||
{
|
{
|
||||||
if((pu8Data[(u32DataIndex+49+u8FirstDotIndex)] == 0x2e))
|
//magic byte found
|
||||||
{
|
while ((u8FirstDotIndex < 3) && (u32FirstDotOffset == 0))
|
||||||
//first dot found
|
{
|
||||||
u32FirstDotOffset = (u32DataIndex+49+u8FirstDotIndex);
|
//search first dot in version number
|
||||||
}
|
if((u32DataIndex+49+u8FirstDotIndex) < *pu32DataLenght)
|
||||||
}
|
{
|
||||||
u8FirstDotIndex++;
|
if((pu8Data[(u32DataIndex+49+u8FirstDotIndex)] == 0x2e))
|
||||||
}
|
{
|
||||||
|
//first dot found
|
||||||
|
u32FirstDotOffset = (u32DataIndex+49+u8FirstDotIndex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
u8FirstDotIndex++;
|
||||||
|
}
|
||||||
|
|
||||||
while ((u8SecondDotIndex < 3) && (u32SecondDotOffset == 0) && (u32FirstDotOffset != 0))
|
while ((u8SecondDotIndex < 3) && (u32SecondDotOffset == 0) && (u32FirstDotOffset != 0))
|
||||||
{
|
{
|
||||||
//search first dot in version number
|
//search first dot in version number
|
||||||
if((u32FirstDotOffset+(u8SecondDotIndex+2)) < *pu32DataLenght)
|
if((u32FirstDotOffset+(u8SecondDotIndex+2)) < *pu32DataLenght)
|
||||||
{
|
{
|
||||||
if((pu8Data[(u32FirstDotOffset+(u8SecondDotIndex+2))] == 0x2e))
|
if((pu8Data[(u32FirstDotOffset+(u8SecondDotIndex+2))] == 0x2e))
|
||||||
{
|
{
|
||||||
//second dot found
|
//second dot found
|
||||||
u32SecondDotOffset = (u32FirstDotOffset+(u8SecondDotIndex+2));
|
u32SecondDotOffset = (u32FirstDotOffset+(u8SecondDotIndex+2));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
u8SecondDotIndex++;
|
u8SecondDotIndex++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if((u32FirstDotOffset != 0) && (u32SecondDotOffset != 0))
|
if((u32FirstDotOffset != 0) && (u32SecondDotOffset != 0))
|
||||||
{
|
{
|
||||||
//image start found based on magic byte and version number systax
|
//image start found based on magic byte and version number systax
|
||||||
*pu32StartOffset = u32DataIndex; //store image start offset
|
*pu32StartOffset = u32DataIndex; //store image start offset
|
||||||
bImageStartOffsetFound = true;
|
bImageStartOffsetFound = true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// this is propably not the magic byte --> reset
|
// this is propably not the magic byte --> reset
|
||||||
u32FirstDotOffset = 0;
|
u32FirstDotOffset = 0;
|
||||||
u32SecondDotOffset = 0;
|
u32SecondDotOffset = 0;
|
||||||
u8FirstDotIndex = 0;
|
u8FirstDotIndex = 0;
|
||||||
u8SecondDotIndex = 0;
|
u8SecondDotIndex = 0;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
u32DataIndex++;
|
||||||
}
|
}
|
||||||
u32DataIndex++;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(bImageStartOffsetFound == false)
|
if(bImageStartOffsetFound == false)
|
||||||
{
|
{
|
||||||
errReturn = ESP_ERR_NOT_FOUND;
|
errReturn = ESP_ERR_NOT_FOUND;
|
||||||
}
|
}
|
||||||
|
|
||||||
return errReturn;
|
return errReturn;
|
||||||
}
|
}
|
||||||
|
@ -119,17 +267,15 @@ esp_err_t errExtractVersionNumber(const char* pu8Data, uint32_t* pu32DataLenght,
|
||||||
err = errFindImageStart(pu8Data, pu32DataLenght, &u32StartOffset); //get image start offset
|
err = errFindImageStart(pu8Data, pu32DataLenght, &u32StartOffset); //get image start offset
|
||||||
|
|
||||||
if(err == ESP_OK)
|
if(err == ESP_OK)
|
||||||
{
|
{
|
||||||
//image found
|
//image found
|
||||||
strncpy(pc8RemoteVersionNumber, pu8Data+(u32StartOffset+48), 11); //copy version number
|
strncpy(pc8RemoteVersionNumber, pu8Data+(u32StartOffset+48), 11); //copy version number
|
||||||
pc8RemoteVersionNumber[12] = '\0';
|
pc8RemoteVersionNumber[12] = '\0';
|
||||||
}
|
}
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
||||||
|
|
||||||
esp_err_t esp_mesh_ota_send(mesh_addr_t* dest)
|
esp_err_t esp_mesh_ota_send(mesh_addr_t* dest)
|
||||||
{
|
{
|
||||||
esp_err_t err = ESP_OK;
|
esp_err_t err = ESP_OK;
|
||||||
|
|
|
@ -10,7 +10,9 @@ bool bIsMeshConnected;
|
||||||
int32_t i32MeshLayer;
|
int32_t i32MeshLayer;
|
||||||
mesh_addr_t meshParentAddr;
|
mesh_addr_t meshParentAddr;
|
||||||
void (*pAppRxHandle)(uint8_t*, uint8_t* );
|
void (*pAppRxHandle)(uint8_t*, uint8_t* );
|
||||||
|
void (*pOTAChildConnectHandle)(uint8_t* );
|
||||||
|
void (*pOTAMessageHandle)(MESH_PACKET_t* );
|
||||||
|
void (*pChangeStateOfServerWorkerHandle)(bool );
|
||||||
|
|
||||||
esp_err_t errMeshNetworkInitialize()
|
esp_err_t errMeshNetworkInitialize()
|
||||||
{
|
{
|
||||||
|
@ -24,9 +26,9 @@ esp_err_t errMeshNetworkInitialize()
|
||||||
|
|
||||||
#ifdef ERASE_NVS
|
#ifdef ERASE_NVS
|
||||||
if(err == ESP_ERR_NVS_NO_FREE_PAGES) //check if storage is full
|
if(err == ESP_ERR_NVS_NO_FREE_PAGES) //check if storage is full
|
||||||
{
|
{
|
||||||
ERROR_CHECK(nvs_flash_erase());
|
ERROR_CHECK(nvs_flash_erase());
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// tcpip initialization
|
// tcpip initialization
|
||||||
|
@ -120,13 +122,13 @@ bool bCheckMACEquality(uint8_t* pu8aMAC, uint8_t* pu8bMAC)
|
||||||
uint8_t index = 0;
|
uint8_t index = 0;
|
||||||
|
|
||||||
while ((index < 6) && (bRet == true))
|
while ((index < 6) && (bRet == true))
|
||||||
{
|
|
||||||
if(pu8aMAC[index] != pu8bMAC[index])
|
|
||||||
{
|
{
|
||||||
bRet = false;
|
if(pu8aMAC[index] != pu8bMAC[index])
|
||||||
|
{
|
||||||
|
bRet = false;
|
||||||
|
}
|
||||||
|
index++;
|
||||||
}
|
}
|
||||||
index++;
|
|
||||||
}
|
|
||||||
return bRet;
|
return bRet;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -139,18 +141,18 @@ esp_err_t errGetChildren(mesh_addr_t* pChildren, uint16_t* pu16ChildrenSize)
|
||||||
ERROR_CHECK(esp_mesh_get_routing_table((mesh_addr_t *) &route_table, (CONFIG_MESH_ROUTE_TABLE_SIZE * 6), &route_table_size));
|
ERROR_CHECK(esp_mesh_get_routing_table((mesh_addr_t *) &route_table, (CONFIG_MESH_ROUTE_TABLE_SIZE * 6), &route_table_size));
|
||||||
|
|
||||||
if (err == ESP_OK)
|
if (err == ESP_OK)
|
||||||
{
|
|
||||||
for(uint16_t index = 0; index < esp_mesh_get_routing_table_size(); index++)
|
|
||||||
{
|
{
|
||||||
if(! (bCheckMACEquality(u8ownMAC, route_table[index].addr)) )
|
for(uint16_t index = 0; index < esp_mesh_get_routing_table_size(); index++)
|
||||||
{
|
{
|
||||||
//child node
|
if(! (bCheckMACEquality(u8ownMAC, route_table[index].addr)) )
|
||||||
//ESP_LOGI(MESH_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]);
|
{
|
||||||
pChildren[*pu16ChildrenSize] = route_table[index];
|
//child node
|
||||||
*pu16ChildrenSize = (*pu16ChildrenSize)+1;
|
//ESP_LOGI(MESH_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]);
|
||||||
}
|
pChildren[*pu16ChildrenSize] = route_table[index];
|
||||||
|
*pu16ChildrenSize = (*pu16ChildrenSize)+1;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -159,13 +161,13 @@ esp_err_t errGetParentNode(mesh_addr_t* pMeshParentAddr)
|
||||||
esp_err_t err = ESP_OK;
|
esp_err_t err = ESP_OK;
|
||||||
|
|
||||||
if(bIsMeshConnected == false)
|
if(bIsMeshConnected == false)
|
||||||
{
|
{
|
||||||
err = ESP_FAIL;
|
err = ESP_FAIL;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
memcpy(pMeshParentAddr, &meshParentAddr, sizeof(mesh_addr_t));
|
memcpy(pMeshParentAddr, &meshParentAddr, sizeof(mesh_addr_t));
|
||||||
}
|
}
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -185,6 +187,24 @@ esp_err_t errMeshNetworkSetAppReceiveHandle(void (*pAppRxHandleTmp)(uint8_t * pu
|
||||||
return ESP_OK;
|
return ESP_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
esp_err_t errMeshNetworkSetChildConnectedHandle(void (*pChildConnectHandleTmp)(uint8_t * pu8Data))
|
||||||
|
{
|
||||||
|
pOTAChildConnectHandle = pChildConnectHandleTmp;
|
||||||
|
return ESP_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
esp_err_t errMeshNetworkSetOTAMessageHandleHandle(void (*pOTAMessageHandleTmp)(MESH_PACKET_t* puMeshPacket))
|
||||||
|
{
|
||||||
|
pOTAMessageHandle = pOTAMessageHandleTmp;
|
||||||
|
return ESP_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
esp_err_t errMeshNetworkSetChangeStateOfServerWorkerHandle(void (*pChangeStateOfServerWorkerHandleTmp)(bool bState))
|
||||||
|
{
|
||||||
|
pChangeStateOfServerWorkerHandle = pChangeStateOfServerWorkerHandleTmp;
|
||||||
|
return ESP_OK;
|
||||||
|
}
|
||||||
|
|
||||||
esp_err_t errSendMeshPacket(mesh_addr_t* pAddrDest, MESH_PACKET_t* pPacket)
|
esp_err_t errSendMeshPacket(mesh_addr_t* pAddrDest, MESH_PACKET_t* pPacket)
|
||||||
{
|
{
|
||||||
esp_err_t err;
|
esp_err_t err;
|
||||||
|
@ -208,9 +228,9 @@ esp_err_t errStartReceiveTask()
|
||||||
xReturned = xTaskCreate(vTaskReceiveMeshData, "ReceiveMeshData", 7000, NULL, 5, NULL);
|
xReturned = xTaskCreate(vTaskReceiveMeshData, "ReceiveMeshData", 7000, NULL, 5, NULL);
|
||||||
|
|
||||||
if(xReturned != pdPASS)
|
if(xReturned != pdPASS)
|
||||||
{
|
{
|
||||||
err = ESP_FAIL;
|
err = ESP_FAIL;
|
||||||
}
|
}
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -224,44 +244,44 @@ void vTaskReceiveMeshData(void *arg)
|
||||||
data.size = CONFIG_MESH_MESSAGE_SIZE;
|
data.size = CONFIG_MESH_MESSAGE_SIZE;
|
||||||
|
|
||||||
while (true)
|
while (true)
|
||||||
{
|
|
||||||
data.size = CONFIG_MESH_MESSAGE_SIZE;
|
|
||||||
err = esp_mesh_recv(&from, &data, portMAX_DELAY, &flag, NULL, 0);
|
|
||||||
if (err != ESP_OK || !data.size)
|
|
||||||
{
|
{
|
||||||
ESP_LOGE(LOG_TAG, "err:0x%x, size:%d", err, data.size);
|
data.size = CONFIG_MESH_MESSAGE_SIZE;
|
||||||
continue;
|
err = esp_mesh_recv(&from, &data, portMAX_DELAY, &flag, NULL, 0);
|
||||||
}
|
if (err != ESP_OK || !data.size)
|
||||||
MESH_PACKET_t packet;
|
{
|
||||||
memcpy(&packet, (uint8_t *)rx_buf, sizeof(MESH_PACKET_t));
|
ESP_LOGE(LOG_TAG, "err:0x%x, size:%d", err, data.size);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
MESH_PACKET_t packet;
|
||||||
|
memcpy(&packet, (uint8_t *)rx_buf, sizeof(MESH_PACKET_t));
|
||||||
|
|
||||||
switch (packet.type)
|
switch (packet.type)
|
||||||
{
|
{
|
||||||
case APP_Data:
|
case APP_Data:
|
||||||
ESP_LOGD(LOG_TAG, "recv: APP_Data");
|
ESP_LOGD(LOG_TAG, "recv: APP_Data");
|
||||||
//call the rx handle from app
|
//call the rx handle from app
|
||||||
pAppRxHandle(packet.au8Payload, from.addr); //hand over payload and sender of this mesh packet
|
pAppRxHandle(packet.au8Payload, from.addr); //hand over payload and sender of this mesh packet
|
||||||
break;
|
break;
|
||||||
case OTA_Version_Request:
|
case OTA_Version_Request:
|
||||||
ESP_LOGI(LOG_TAG, "recv: OTA_Version_Request");
|
ESP_LOGI(LOG_TAG, "recv: OTA_Version_Request");
|
||||||
break;
|
break;
|
||||||
case OTA_Version_Respone:
|
case OTA_Version_Respone:
|
||||||
ESP_LOGI(LOG_TAG, "recv: OTA_Version_Respone");
|
ESP_LOGI(LOG_TAG, "recv: OTA_Version_Respone");
|
||||||
break;
|
break;
|
||||||
case OTA_Data:
|
case OTA_Data:
|
||||||
ESP_LOGI(LOG_TAG, "recv: OTA_Data");
|
ESP_LOGI(LOG_TAG, "recv: OTA_Data");
|
||||||
break;
|
break;
|
||||||
case OTA_ACK:
|
case OTA_ACK:
|
||||||
ESP_LOGI(LOG_TAG, "recv: OTA_ACK");
|
ESP_LOGI(LOG_TAG, "recv: OTA_ACK");
|
||||||
break;
|
break;
|
||||||
case OTA_Complete:
|
case OTA_Complete:
|
||||||
ESP_LOGI(LOG_TAG, "recv: OTA_Complete");
|
ESP_LOGI(LOG_TAG, "recv: OTA_Complete");
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
ESP_LOGE(LOG_TAG, "recv: something");
|
ESP_LOGE(LOG_TAG, "recv: something");
|
||||||
break;
|
break;
|
||||||
}//end switch
|
}//end switch
|
||||||
} //end while
|
} //end while
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,10 @@ void vIPEventHandler(void *arg, esp_event_base_t event_base, int32_t i32EventID,
|
||||||
{
|
{
|
||||||
ip_event_got_ip_t *event = (ip_event_got_ip_t *) vpEventData;
|
ip_event_got_ip_t *event = (ip_event_got_ip_t *) vpEventData;
|
||||||
ESP_LOGI(LOG_TAG, "<IP_EVENT_STA_GOT_IP>IP:" IPSTR, IP2STR(&event->ip_info.ip));
|
ESP_LOGI(LOG_TAG, "<IP_EVENT_STA_GOT_IP>IP:" IPSTR, IP2STR(&event->ip_info.ip));
|
||||||
|
if(pChangeStateOfServerWorkerHandle)
|
||||||
|
{
|
||||||
|
pChangeStateOfServerWorkerHandle(true); //signal that this node (root node) has access to internet
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void vMeshEventHandler(void *arg, esp_event_base_t event_base, int32_t i32EventID, void* vpEventData)
|
void vMeshEventHandler(void *arg, esp_event_base_t event_base, int32_t i32EventID, void* vpEventData)
|
||||||
|
@ -15,205 +19,210 @@ void vMeshEventHandler(void *arg, esp_event_base_t event_base, int32_t i32EventI
|
||||||
static uint16_t last_layer = 0;
|
static uint16_t last_layer = 0;
|
||||||
|
|
||||||
switch (i32EventID)
|
switch (i32EventID)
|
||||||
{
|
|
||||||
case MESH_EVENT_STARTED:
|
|
||||||
{
|
|
||||||
esp_mesh_get_id(&id);
|
|
||||||
ESP_LOGI(LOG_TAG, "<MESH_EVENT_MESH_STARTED>ID:"MACSTR"", MAC2STR(id.addr));
|
|
||||||
bIsMeshConnected = false;
|
|
||||||
i32MeshLayer = esp_mesh_get_layer();
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case MESH_EVENT_STOPPED:
|
|
||||||
{
|
|
||||||
ESP_LOGI(LOG_TAG, "<MESH_EVENT_STOPPED>");
|
|
||||||
bIsMeshConnected = false;
|
|
||||||
i32MeshLayer = esp_mesh_get_layer();
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case MESH_EVENT_CHILD_CONNECTED:
|
|
||||||
{
|
|
||||||
mesh_event_child_connected_t *child_connected = (mesh_event_child_connected_t *)vpEventData;
|
|
||||||
ESP_LOGI(LOG_TAG, "<MESH_EVENT_CHILD_CONNECTED>aid:%d, "MACSTR"",
|
|
||||||
child_connected->aid,
|
|
||||||
MAC2STR(child_connected->mac));
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case MESH_EVENT_CHILD_DISCONNECTED:
|
|
||||||
{
|
|
||||||
mesh_event_child_disconnected_t *child_disconnected = (mesh_event_child_disconnected_t *)vpEventData;
|
|
||||||
ESP_LOGI(LOG_TAG, "<MESH_EVENT_CHILD_DISCONNECTED>aid:%d, "MACSTR"",
|
|
||||||
child_disconnected->aid,
|
|
||||||
MAC2STR(child_disconnected->mac));
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case MESH_EVENT_ROUTING_TABLE_ADD:
|
|
||||||
{
|
|
||||||
mesh_event_routing_table_change_t *routing_table = (mesh_event_routing_table_change_t *)vpEventData;
|
|
||||||
ESP_LOGW(LOG_TAG, "<MESH_EVENT_ROUTING_TABLE_ADD>add %d, new:%d, layer:%d",
|
|
||||||
routing_table->rt_size_change,
|
|
||||||
routing_table->rt_size_new, i32MeshLayer);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case MESH_EVENT_ROUTING_TABLE_REMOVE:
|
|
||||||
{
|
|
||||||
mesh_event_routing_table_change_t *routing_table = (mesh_event_routing_table_change_t *)vpEventData;
|
|
||||||
ESP_LOGW(LOG_TAG, "<MESH_EVENT_ROUTING_TABLE_REMOVE>remove %d, new:%d, layer:%d",
|
|
||||||
routing_table->rt_size_change,
|
|
||||||
routing_table->rt_size_new, i32MeshLayer);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case MESH_EVENT_NO_PARENT_FOUND:
|
|
||||||
{
|
|
||||||
mesh_event_no_parent_found_t *no_parent = (mesh_event_no_parent_found_t *)vpEventData;
|
|
||||||
ESP_LOGI(LOG_TAG, "<MESH_EVENT_NO_PARENT_FOUND>scan times:%d",
|
|
||||||
no_parent->scan_times);
|
|
||||||
/* TODO handler for the failure, maybe nominate themselves */
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case MESH_EVENT_PARENT_CONNECTED:
|
|
||||||
{
|
|
||||||
mesh_event_connected_t *connected = (mesh_event_connected_t *)vpEventData;
|
|
||||||
esp_mesh_get_id(&id);
|
|
||||||
i32MeshLayer = connected->self_layer;
|
|
||||||
memcpy(&meshParentAddr.addr, connected->connected.bssid, 6);
|
|
||||||
ESP_LOGI(LOG_TAG, "<MESH_EVENT_PARENT_CONNECTED>layer:%d-->%d, parent:"MACSTR"%s, ID:"MACSTR", duty:%d",
|
|
||||||
last_layer, i32MeshLayer, MAC2STR(meshParentAddr.addr),
|
|
||||||
esp_mesh_is_root() ? "<ROOT>" : (i32MeshLayer == 2) ? "<layer2>" : "", //print own node title
|
|
||||||
MAC2STR(id.addr), connected->duty);
|
|
||||||
last_layer = i32MeshLayer;
|
|
||||||
bIsMeshConnected = true;
|
|
||||||
if (esp_mesh_is_root())
|
|
||||||
{
|
{
|
||||||
ESP_ERROR_CHECK(esp_netif_dhcpc_start(netif_sta)); //get a IP from router
|
case MESH_EVENT_STARTED:
|
||||||
}
|
{
|
||||||
errStartReceiveTask();//start receiving
|
esp_mesh_get_id(&id);
|
||||||
}
|
ESP_LOGI(LOG_TAG, "<MESH_EVENT_MESH_STARTED>ID:"MACSTR"", MAC2STR(id.addr));
|
||||||
break;
|
bIsMeshConnected = false;
|
||||||
|
i32MeshLayer = esp_mesh_get_layer();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case MESH_EVENT_STOPPED:
|
||||||
|
{
|
||||||
|
ESP_LOGI(LOG_TAG, "<MESH_EVENT_STOPPED>");
|
||||||
|
bIsMeshConnected = false;
|
||||||
|
i32MeshLayer = esp_mesh_get_layer();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case MESH_EVENT_CHILD_CONNECTED:
|
||||||
|
{
|
||||||
|
mesh_event_child_connected_t *child_connected = (mesh_event_child_connected_t *)vpEventData;
|
||||||
|
ESP_LOGI(LOG_TAG, "<MESH_EVENT_CHILD_CONNECTED>aid:%d, "MACSTR"", child_connected->aid, MAC2STR(child_connected->mac));
|
||||||
|
|
||||||
|
if(pOTAChildConnectHandle){pOTAChildConnectHandle(child_connected->mac);}//add this child to queue using handle
|
||||||
|
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case MESH_EVENT_CHILD_DISCONNECTED:
|
||||||
|
{
|
||||||
|
mesh_event_child_disconnected_t *child_disconnected = (mesh_event_child_disconnected_t *)vpEventData;
|
||||||
|
ESP_LOGI(LOG_TAG, "<MESH_EVENT_CHILD_DISCONNECTED>aid:%d, "MACSTR"",
|
||||||
|
child_disconnected->aid,
|
||||||
|
MAC2STR(child_disconnected->mac));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case MESH_EVENT_ROUTING_TABLE_ADD:
|
||||||
|
{
|
||||||
|
mesh_event_routing_table_change_t *routing_table = (mesh_event_routing_table_change_t *)vpEventData;
|
||||||
|
ESP_LOGW(LOG_TAG, "<MESH_EVENT_ROUTING_TABLE_ADD>add %d, new:%d, layer:%d",
|
||||||
|
routing_table->rt_size_change,
|
||||||
|
routing_table->rt_size_new, i32MeshLayer);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case MESH_EVENT_ROUTING_TABLE_REMOVE:
|
||||||
|
{
|
||||||
|
mesh_event_routing_table_change_t *routing_table = (mesh_event_routing_table_change_t *)vpEventData;
|
||||||
|
ESP_LOGW(LOG_TAG, "<MESH_EVENT_ROUTING_TABLE_REMOVE>remove %d, new:%d, layer:%d",
|
||||||
|
routing_table->rt_size_change,
|
||||||
|
routing_table->rt_size_new, i32MeshLayer);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case MESH_EVENT_NO_PARENT_FOUND:
|
||||||
|
{
|
||||||
|
mesh_event_no_parent_found_t *no_parent = (mesh_event_no_parent_found_t *)vpEventData;
|
||||||
|
ESP_LOGI(LOG_TAG, "<MESH_EVENT_NO_PARENT_FOUND>scan times:%d",
|
||||||
|
no_parent->scan_times);
|
||||||
|
/* TODO handler for the failure, maybe nominate themselves */
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case MESH_EVENT_PARENT_CONNECTED:
|
||||||
|
{
|
||||||
|
mesh_event_connected_t *connected = (mesh_event_connected_t *)vpEventData;
|
||||||
|
esp_mesh_get_id(&id);
|
||||||
|
i32MeshLayer = connected->self_layer;
|
||||||
|
memcpy(&meshParentAddr.addr, connected->connected.bssid, 6);
|
||||||
|
ESP_LOGI(LOG_TAG, "<MESH_EVENT_PARENT_CONNECTED>layer:%d-->%d, parent:"MACSTR"%s, ID:"MACSTR", duty:%d",
|
||||||
|
last_layer, i32MeshLayer, MAC2STR(meshParentAddr.addr),
|
||||||
|
esp_mesh_is_root() ? "<ROOT>" : (i32MeshLayer == 2) ? "<layer2>" : "", //print own node title
|
||||||
|
MAC2STR(id.addr), connected->duty);
|
||||||
|
last_layer = i32MeshLayer;
|
||||||
|
bIsMeshConnected = true;
|
||||||
|
if (esp_mesh_is_root())
|
||||||
|
{
|
||||||
|
if(esp_netif_dhcpc_start(netif_sta) == ESP_ERR_ESP_NETIF_DHCP_ALREADY_STARTED) //get a IP from router
|
||||||
|
{
|
||||||
|
if(pChangeStateOfServerWorkerHandle){pChangeStateOfServerWorkerHandle(true);}// signal reconnect
|
||||||
|
}
|
||||||
|
}
|
||||||
|
errStartReceiveTask();//start receiving
|
||||||
|
}
|
||||||
|
break;
|
||||||
case MESH_EVENT_PARENT_DISCONNECTED:
|
case MESH_EVENT_PARENT_DISCONNECTED:
|
||||||
{
|
{
|
||||||
mesh_event_disconnected_t *disconnected = (mesh_event_disconnected_t *)vpEventData;
|
mesh_event_disconnected_t *disconnected = (mesh_event_disconnected_t *)vpEventData;
|
||||||
ESP_LOGI(LOG_TAG, "<MESH_EVENT_PARENT_DISCONNECTED>reason:%d", disconnected->reason);
|
ESP_LOGI(LOG_TAG, "<MESH_EVENT_PARENT_DISCONNECTED>reason:%d", disconnected->reason);
|
||||||
bIsMeshConnected = false;
|
bIsMeshConnected = false;
|
||||||
i32MeshLayer = esp_mesh_get_layer();
|
if(pChangeStateOfServerWorkerHandle){pChangeStateOfServerWorkerHandle(false);}
|
||||||
}
|
i32MeshLayer = esp_mesh_get_layer();
|
||||||
break;
|
}
|
||||||
|
break;
|
||||||
case MESH_EVENT_LAYER_CHANGE:
|
case MESH_EVENT_LAYER_CHANGE:
|
||||||
{
|
{
|
||||||
mesh_event_layer_change_t *layer_change = (mesh_event_layer_change_t *)vpEventData;
|
mesh_event_layer_change_t *layer_change = (mesh_event_layer_change_t *)vpEventData;
|
||||||
i32MeshLayer = layer_change->new_layer;
|
i32MeshLayer = layer_change->new_layer;
|
||||||
ESP_LOGI(LOG_TAG, "<MESH_EVENT_LAYER_CHANGE>layer:%d-->%d%s",
|
ESP_LOGI(LOG_TAG, "<MESH_EVENT_LAYER_CHANGE>layer:%d-->%d%s",
|
||||||
last_layer, i32MeshLayer,
|
last_layer, i32MeshLayer,
|
||||||
esp_mesh_is_root() ? "<ROOT>" : (i32MeshLayer == 2) ? "<layer2>" : "");
|
esp_mesh_is_root() ? "<ROOT>" : (i32MeshLayer == 2) ? "<layer2>" : "");
|
||||||
last_layer = i32MeshLayer;
|
last_layer = i32MeshLayer;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case MESH_EVENT_ROOT_ADDRESS:
|
case MESH_EVENT_ROOT_ADDRESS:
|
||||||
{
|
{
|
||||||
mesh_event_root_address_t *root_addr = (mesh_event_root_address_t *)vpEventData;
|
mesh_event_root_address_t *root_addr = (mesh_event_root_address_t *)vpEventData;
|
||||||
ESP_LOGI(LOG_TAG, "<MESH_EVENT_ROOT_ADDRESS>root address:"MACSTR"",
|
ESP_LOGI(LOG_TAG, "<MESH_EVENT_ROOT_ADDRESS>root address:"MACSTR"",
|
||||||
MAC2STR(root_addr->addr));
|
MAC2STR(root_addr->addr));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case MESH_EVENT_VOTE_STARTED:
|
case MESH_EVENT_VOTE_STARTED:
|
||||||
{
|
{
|
||||||
mesh_event_vote_started_t *vote_started = (mesh_event_vote_started_t *)vpEventData;
|
mesh_event_vote_started_t *vote_started = (mesh_event_vote_started_t *)vpEventData;
|
||||||
ESP_LOGI(LOG_TAG, "<MESH_EVENT_VOTE_STARTED>attempts:%d, reason:%d, rc_addr:"MACSTR"",
|
ESP_LOGI(LOG_TAG, "<MESH_EVENT_VOTE_STARTED>attempts:%d, reason:%d, rc_addr:"MACSTR"",
|
||||||
vote_started->attempts,
|
vote_started->attempts,
|
||||||
vote_started->reason,
|
vote_started->reason,
|
||||||
MAC2STR(vote_started->rc_addr.addr));
|
MAC2STR(vote_started->rc_addr.addr));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case MESH_EVENT_VOTE_STOPPED:
|
case MESH_EVENT_VOTE_STOPPED:
|
||||||
{
|
{
|
||||||
ESP_LOGI(LOG_TAG, "<MESH_EVENT_VOTE_STOPPED>");
|
ESP_LOGI(LOG_TAG, "<MESH_EVENT_VOTE_STOPPED>");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case MESH_EVENT_ROOT_SWITCH_REQ:
|
case MESH_EVENT_ROOT_SWITCH_REQ:
|
||||||
{
|
{
|
||||||
mesh_event_root_switch_req_t *switch_req = (mesh_event_root_switch_req_t *)vpEventData;
|
mesh_event_root_switch_req_t *switch_req = (mesh_event_root_switch_req_t *)vpEventData;
|
||||||
ESP_LOGI(LOG_TAG, "<MESH_EVENT_ROOT_SWITCH_REQ>reason:%d, rc_addr:"MACSTR"", switch_req->reason,
|
ESP_LOGI(LOG_TAG, "<MESH_EVENT_ROOT_SWITCH_REQ>reason:%d, rc_addr:"MACSTR"", switch_req->reason,
|
||||||
MAC2STR( switch_req->rc_addr.addr));
|
MAC2STR( switch_req->rc_addr.addr));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case MESH_EVENT_ROOT_SWITCH_ACK:
|
case MESH_EVENT_ROOT_SWITCH_ACK:
|
||||||
{
|
{
|
||||||
//new root
|
//new root
|
||||||
i32MeshLayer = esp_mesh_get_layer();
|
i32MeshLayer = esp_mesh_get_layer();
|
||||||
esp_mesh_get_parent_bssid(&meshParentAddr);
|
esp_mesh_get_parent_bssid(&meshParentAddr);
|
||||||
ESP_LOGI(LOG_TAG, "<MESH_EVENT_ROOT_SWITCH_ACK>layer:%d, parent:"MACSTR"", i32MeshLayer, MAC2STR(meshParentAddr.addr));
|
ESP_LOGI(LOG_TAG, "<MESH_EVENT_ROOT_SWITCH_ACK>layer:%d, parent:"MACSTR"", i32MeshLayer, MAC2STR(meshParentAddr.addr));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case MESH_EVENT_TODS_STATE:
|
case MESH_EVENT_TODS_STATE:
|
||||||
{
|
{
|
||||||
mesh_event_toDS_state_t *toDs_state = (mesh_event_toDS_state_t *)vpEventData;
|
mesh_event_toDS_state_t *toDs_state = (mesh_event_toDS_state_t *)vpEventData;
|
||||||
ESP_LOGI(LOG_TAG, "<MESH_EVENT_TODS_REACHABLE>state:%d", *toDs_state);
|
ESP_LOGI(LOG_TAG, "<MESH_EVENT_TODS_REACHABLE>state:%d", *toDs_state);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case MESH_EVENT_ROOT_FIXED:
|
case MESH_EVENT_ROOT_FIXED:
|
||||||
{
|
{
|
||||||
mesh_event_root_fixed_t *root_fixed = (mesh_event_root_fixed_t *)vpEventData;
|
mesh_event_root_fixed_t *root_fixed = (mesh_event_root_fixed_t *)vpEventData;
|
||||||
ESP_LOGI(LOG_TAG, "<MESH_EVENT_ROOT_FIXED>%s",
|
ESP_LOGI(LOG_TAG, "<MESH_EVENT_ROOT_FIXED>%s",
|
||||||
root_fixed->is_fixed ? "fixed" : "not fixed");
|
root_fixed->is_fixed ? "fixed" : "not fixed");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case MESH_EVENT_ROOT_ASKED_YIELD:
|
case MESH_EVENT_ROOT_ASKED_YIELD:
|
||||||
{
|
{
|
||||||
mesh_event_root_conflict_t *root_conflict = (mesh_event_root_conflict_t *)vpEventData;
|
mesh_event_root_conflict_t *root_conflict = (mesh_event_root_conflict_t *)vpEventData;
|
||||||
ESP_LOGI(LOG_TAG, "<MESH_EVENT_ROOT_ASKED_YIELD>"MACSTR", rssi:%d, capacity:%d",
|
ESP_LOGI(LOG_TAG, "<MESH_EVENT_ROOT_ASKED_YIELD>"MACSTR", rssi:%d, capacity:%d",
|
||||||
MAC2STR(root_conflict->addr), root_conflict->rssi, root_conflict->capacity);
|
MAC2STR(root_conflict->addr), root_conflict->rssi, root_conflict->capacity);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case MESH_EVENT_CHANNEL_SWITCH:
|
case MESH_EVENT_CHANNEL_SWITCH:
|
||||||
{
|
{
|
||||||
mesh_event_channel_switch_t *channel_switch = (mesh_event_channel_switch_t *)vpEventData;
|
mesh_event_channel_switch_t *channel_switch = (mesh_event_channel_switch_t *)vpEventData;
|
||||||
ESP_LOGI(LOG_TAG, "<MESH_EVENT_CHANNEL_SWITCH>new channel:%d", channel_switch->channel);
|
ESP_LOGI(LOG_TAG, "<MESH_EVENT_CHANNEL_SWITCH>new channel:%d", channel_switch->channel);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case MESH_EVENT_SCAN_DONE:
|
case MESH_EVENT_SCAN_DONE:
|
||||||
{
|
{
|
||||||
mesh_event_scan_done_t *scan_done = (mesh_event_scan_done_t *)vpEventData;
|
mesh_event_scan_done_t *scan_done = (mesh_event_scan_done_t *)vpEventData;
|
||||||
ESP_LOGI(LOG_TAG, "<MESH_EVENT_SCAN_DONE>number:%d", scan_done->number);
|
ESP_LOGI(LOG_TAG, "<MESH_EVENT_SCAN_DONE>number:%d", scan_done->number);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case MESH_EVENT_NETWORK_STATE:
|
case MESH_EVENT_NETWORK_STATE:
|
||||||
{
|
{
|
||||||
mesh_event_network_state_t *network_state = (mesh_event_network_state_t *)vpEventData;
|
mesh_event_network_state_t *network_state = (mesh_event_network_state_t *)vpEventData;
|
||||||
ESP_LOGI(LOG_TAG, "<MESH_EVENT_NETWORK_STATE>is_rootless:%d", network_state->is_rootless);
|
ESP_LOGI(LOG_TAG, "<MESH_EVENT_NETWORK_STATE>is_rootless:%d", network_state->is_rootless);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case MESH_EVENT_STOP_RECONNECTION:
|
case MESH_EVENT_STOP_RECONNECTION:
|
||||||
{
|
{
|
||||||
ESP_LOGI(LOG_TAG, "<MESH_EVENT_STOP_RECONNECTION>");
|
ESP_LOGI(LOG_TAG, "<MESH_EVENT_STOP_RECONNECTION>");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case MESH_EVENT_FIND_NETWORK:
|
case MESH_EVENT_FIND_NETWORK:
|
||||||
{
|
{
|
||||||
mesh_event_find_network_t *find_network = (mesh_event_find_network_t *)vpEventData;
|
mesh_event_find_network_t *find_network = (mesh_event_find_network_t *)vpEventData;
|
||||||
ESP_LOGI(LOG_TAG, "<MESH_EVENT_FIND_NETWORK>new channel:%d, router BSSID:"MACSTR"",
|
ESP_LOGI(LOG_TAG, "<MESH_EVENT_FIND_NETWORK>new channel:%d, router BSSID:"MACSTR"",
|
||||||
find_network->channel, MAC2STR(find_network->router_bssid));
|
find_network->channel, MAC2STR(find_network->router_bssid));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case MESH_EVENT_ROUTER_SWITCH:
|
case MESH_EVENT_ROUTER_SWITCH:
|
||||||
{
|
{
|
||||||
mesh_event_router_switch_t *router_switch = (mesh_event_router_switch_t *)vpEventData;
|
mesh_event_router_switch_t *router_switch = (mesh_event_router_switch_t *)vpEventData;
|
||||||
ESP_LOGI(LOG_TAG, "<MESH_EVENT_ROUTER_SWITCH>new router:%s, channel:%d, "MACSTR"",
|
ESP_LOGI(LOG_TAG, "<MESH_EVENT_ROUTER_SWITCH>new router:%s, channel:%d, "MACSTR"",
|
||||||
router_switch->ssid, router_switch->channel, MAC2STR(router_switch->bssid));
|
router_switch->ssid, router_switch->channel, MAC2STR(router_switch->bssid));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case MESH_EVENT_PS_PARENT_DUTY:
|
case MESH_EVENT_PS_PARENT_DUTY:
|
||||||
{
|
{
|
||||||
mesh_event_ps_duty_t *ps_duty = (mesh_event_ps_duty_t *)vpEventData;
|
mesh_event_ps_duty_t *ps_duty = (mesh_event_ps_duty_t *)vpEventData;
|
||||||
ESP_LOGI(LOG_TAG, "<MESH_EVENT_PS_PARENT_DUTY>duty:%d", ps_duty->duty);
|
ESP_LOGI(LOG_TAG, "<MESH_EVENT_PS_PARENT_DUTY>duty:%d", ps_duty->duty);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case MESH_EVENT_PS_CHILD_DUTY:
|
case MESH_EVENT_PS_CHILD_DUTY:
|
||||||
{
|
{
|
||||||
mesh_event_ps_duty_t *ps_duty = (mesh_event_ps_duty_t *)vpEventData;
|
mesh_event_ps_duty_t *ps_duty = (mesh_event_ps_duty_t *)vpEventData;
|
||||||
ESP_LOGI(LOG_TAG, "<MESH_EVENT_PS_CHILD_DUTY>cidx:%d, "MACSTR", duty:%d", ps_duty->child_connected.aid-1,
|
ESP_LOGI(LOG_TAG, "<MESH_EVENT_PS_CHILD_DUTY>cidx:%d, "MACSTR", duty:%d", ps_duty->child_connected.aid-1,
|
||||||
MAC2STR(ps_duty->child_connected.mac), ps_duty->duty);
|
MAC2STR(ps_duty->child_connected.mac), ps_duty->duty);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
ESP_LOGI(LOG_TAG, "unknown id:%d", i32EventID);
|
ESP_LOGI(LOG_TAG, "unknown id:%d", i32EventID);
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -23,47 +23,47 @@ https_client_ret_t https_clientInitialize()
|
||||||
i32RetHTTPClient = https_clientInitEmbedTLS();
|
i32RetHTTPClient = https_clientInitEmbedTLS();
|
||||||
|
|
||||||
if(i32RetHTTPClient == HTTPS_CLIENT_OK)
|
if(i32RetHTTPClient == HTTPS_CLIENT_OK)
|
||||||
{
|
{
|
||||||
i32RetHTTPClient = https_clientConnectToServer();
|
i32RetHTTPClient = https_clientConnectToServer();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(i32RetHTTPClient == HTTPS_CLIENT_OK)
|
if(i32RetHTTPClient == HTTPS_CLIENT_OK)
|
||||||
{
|
{
|
||||||
i32RetHTTPClient = https_clientValidateServer();
|
i32RetHTTPClient = https_clientValidateServer();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(i32RetHTTPClient == HTTPS_CLIENT_OK)
|
if(i32RetHTTPClient == HTTPS_CLIENT_OK)
|
||||||
{
|
{
|
||||||
i32RetHTTPClient = https_clientSendRequest();
|
i32RetHTTPClient = https_clientSendRequest();
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (i32RetHTTPClient)
|
switch (i32RetHTTPClient)
|
||||||
{
|
{
|
||||||
case HTTPS_CLIENT_ERROR_INIT_EMBEDTLS:
|
case HTTPS_CLIENT_ERROR_INIT_EMBEDTLS:
|
||||||
ESP_LOGE(TAG, "Unable to initialize EmbedTLS");
|
ESP_LOGE(TAG, "Unable to initialize EmbedTLS");
|
||||||
i32RetHTTPClient = HTTPS_CLIENT_ERROR;
|
i32RetHTTPClient = HTTPS_CLIENT_ERROR;
|
||||||
break;
|
break;
|
||||||
case HTTPS_CLIENT_ERROR_INIT_CONNECT_TWO_SERVER:
|
case HTTPS_CLIENT_ERROR_INIT_CONNECT_TWO_SERVER:
|
||||||
ESP_LOGE(TAG, "Unable to connect to server");
|
ESP_LOGE(TAG, "Unable to connect to server");
|
||||||
i32RetHTTPClient = HTTPS_CLIENT_ERROR;
|
i32RetHTTPClient = HTTPS_CLIENT_ERROR;
|
||||||
break;
|
break;
|
||||||
case HTTPS_CLIENT_ERROR_INIT_VALIDATE_SERVER:
|
case HTTPS_CLIENT_ERROR_INIT_VALIDATE_SERVER:
|
||||||
ESP_LOGE(TAG, "Unable to validate the server");
|
ESP_LOGE(TAG, "Unable to validate the server");
|
||||||
i32RetHTTPClient = HTTPS_CLIENT_ERROR;
|
i32RetHTTPClient = HTTPS_CLIENT_ERROR;
|
||||||
break;
|
break;
|
||||||
case HTTPS_CLIENT_ERROR_INIT_SEND_REQUEST:
|
case HTTPS_CLIENT_ERROR_INIT_SEND_REQUEST:
|
||||||
ESP_LOGE(TAG, "Unable to send request to server");
|
ESP_LOGE(TAG, "Unable to send request to server");
|
||||||
i32RetHTTPClient = HTTPS_CLIENT_ERROR;
|
i32RetHTTPClient = HTTPS_CLIENT_ERROR;
|
||||||
break;
|
break;
|
||||||
case HTTPS_CLIENT_OK:
|
case HTTPS_CLIENT_OK:
|
||||||
ESP_LOGI(TAG, "HTTPS Client successfully initialized");
|
ESP_LOGI(TAG, "HTTPS Client successfully initialized");
|
||||||
i32RetHTTPClient = HTTPS_CLIENT_OK;
|
i32RetHTTPClient = HTTPS_CLIENT_OK;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
i32RetHTTPClient = HTTPS_CLIENT_ERROR;
|
i32RetHTTPClient = HTTPS_CLIENT_ERROR;
|
||||||
ESP_LOGE(TAG, "Unknown error while init https client");
|
ESP_LOGE(TAG, "Unknown error while init https client");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return i32RetHTTPClient;
|
return i32RetHTTPClient;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,41 +77,41 @@ https_client_ret_t https_clientRetrieveData(char* pu8Data, uint32_t* pu32DataLen
|
||||||
*pu32BytesRead = 0U;
|
*pu32BytesRead = 0U;
|
||||||
|
|
||||||
while (bRetriveData)
|
while (bRetriveData)
|
||||||
{
|
|
||||||
//Reading HTTP response
|
|
||||||
i32RetRetrieveData = mbedtls_ssl_read(&sHTTPS_ClientConfig.ssl, (unsigned char *)(pu8Data+(*pu32BytesRead)), ((*pu32DataLenght)-(*pu32BytesRead)));
|
|
||||||
|
|
||||||
if(i32RetRetrieveData > 0)
|
|
||||||
{
|
{
|
||||||
//Data received
|
//Reading HTTP response
|
||||||
*pu32BytesRead = *pu32BytesRead + i32RetRetrieveData;
|
i32RetRetrieveData = mbedtls_ssl_read(&sHTTPS_ClientConfig.ssl, (unsigned char *)(pu8Data+(*pu32BytesRead)), ((*pu32DataLenght)-(*pu32BytesRead)));
|
||||||
|
|
||||||
if(*pu32DataLenght > 0)
|
if(i32RetRetrieveData > 0)
|
||||||
{
|
{
|
||||||
//buffer not full yet --> read some more
|
//Data received
|
||||||
bRetriveData = true;
|
*pu32BytesRead = *pu32BytesRead + i32RetRetrieveData;
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
//buffer full --> stop reading
|
|
||||||
bRetriveData = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(i32RetRetrieveData == 0)
|
if(*pu32DataLenght > 0)
|
||||||
{
|
{
|
||||||
//all data read --> stop reading
|
//buffer not full yet --> read some more
|
||||||
bRetriveData = false;
|
bRetriveData = true;
|
||||||
pu32BytesRead = 0;
|
}
|
||||||
}
|
else
|
||||||
|
{
|
||||||
|
//buffer full --> stop reading
|
||||||
|
bRetriveData = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if(i32RetRetrieveData == MBEDTLS_ERR_SSL_PEER_CLOSE_NOTIFY)
|
if(i32RetRetrieveData == 0)
|
||||||
{
|
{
|
||||||
//connection is going to be closed
|
//all data read --> stop reading
|
||||||
i32RetHTTPClient = HTTPS_CLIENT_ERROR;
|
bRetriveData = false;
|
||||||
bRetriveData = false;
|
pu32BytesRead = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(i32RetRetrieveData == MBEDTLS_ERR_SSL_PEER_CLOSE_NOTIFY)
|
||||||
|
{
|
||||||
|
//connection is going to be closed
|
||||||
|
i32RetHTTPClient = HTTPS_CLIENT_ERROR;
|
||||||
|
bRetriveData = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return i32RetHTTPClient;
|
return i32RetHTTPClient;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -122,9 +122,9 @@ https_client_ret_t https_clientDeinitialize()
|
||||||
i32RetHTTPClient = mbedtls_ssl_close_notify(&sHTTPS_ClientConfig.ssl); //close session
|
i32RetHTTPClient = mbedtls_ssl_close_notify(&sHTTPS_ClientConfig.ssl); //close session
|
||||||
|
|
||||||
if(i32RetHTTPClient != ESP_OK)
|
if(i32RetHTTPClient != ESP_OK)
|
||||||
{
|
{
|
||||||
ESP_LOGE(TAG, "mbedtls_ssl_close_notify returned 0x%x", i32RetHTTPClient);
|
ESP_LOGE(TAG, "mbedtls_ssl_close_notify returned 0x%x", i32RetHTTPClient);
|
||||||
}
|
}
|
||||||
|
|
||||||
mbedtls_ssl_session_reset(&sHTTPS_ClientConfig.ssl); //reset embedssl
|
mbedtls_ssl_session_reset(&sHTTPS_ClientConfig.ssl); //reset embedssl
|
||||||
mbedtls_net_free(&sHTTPS_ClientConfig.server_fd); //free ram
|
mbedtls_net_free(&sHTTPS_ClientConfig.server_fd); //free ram
|
||||||
|
@ -132,7 +132,8 @@ https_client_ret_t https_clientDeinitialize()
|
||||||
return i32RetHTTPClient;
|
return i32RetHTTPClient;
|
||||||
}
|
}
|
||||||
|
|
||||||
https_client_ret_t https_clientInitEmbedTLS() {
|
https_client_ret_t https_clientInitEmbedTLS()
|
||||||
|
{
|
||||||
|
|
||||||
https_client_ret_t i32RetHTTPClient = HTTPS_CLIENT_OK;
|
https_client_ret_t i32RetHTTPClient = HTTPS_CLIENT_OK;
|
||||||
int32_t i32RetEmbedTLS = ESP_OK;
|
int32_t i32RetEmbedTLS = ESP_OK;
|
||||||
|
@ -146,66 +147,66 @@ https_client_ret_t https_clientInitEmbedTLS() {
|
||||||
i32RetEmbedTLS = mbedtls_ctr_drbg_seed(&sHTTPS_ClientConfig.ctr_drbg, mbedtls_entropy_func, &sHTTPS_ClientConfig.entropy, NULL, 0);
|
i32RetEmbedTLS = mbedtls_ctr_drbg_seed(&sHTTPS_ClientConfig.ctr_drbg, mbedtls_entropy_func, &sHTTPS_ClientConfig.entropy, NULL, 0);
|
||||||
|
|
||||||
if(i32RetEmbedTLS!= ESP_OK)
|
if(i32RetEmbedTLS!= ESP_OK)
|
||||||
{
|
|
||||||
ESP_LOGE(TAG, "mbedtls_ctr_drbg_seed returned %d", i32RetEmbedTLS);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(i32RetEmbedTLS == ESP_OK)
|
|
||||||
{
|
|
||||||
//Attaching the certificate bundle
|
|
||||||
i32RetEmbedTLS = esp_crt_bundle_attach(&sHTTPS_ClientConfig.conf);
|
|
||||||
if(i32RetEmbedTLS != ESP_OK)
|
|
||||||
{
|
{
|
||||||
ESP_LOGE(TAG, "esp_crt_bundle_attach returned 0x%x\n\n", i32RetEmbedTLS);
|
ESP_LOGE(TAG, "mbedtls_ctr_drbg_seed returned %d", i32RetEmbedTLS);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if(i32RetEmbedTLS == ESP_OK)
|
if(i32RetEmbedTLS == ESP_OK)
|
||||||
{
|
|
||||||
//Setting hostname for TLS session.
|
|
||||||
i32RetEmbedTLS = mbedtls_ssl_set_hostname(&sHTTPS_ClientConfig.ssl, CONFIG_OTA_HTTPS_SERVER_COMMON_NAME);
|
|
||||||
// Hostname set here should match CN in server certificate
|
|
||||||
if(i32RetEmbedTLS != ESP_OK)
|
|
||||||
{
|
{
|
||||||
ESP_LOGE(TAG, "mbedtls_ssl_set_hostname returned 0x%x", i32RetEmbedTLS);
|
//Attaching the certificate bundle
|
||||||
|
i32RetEmbedTLS = esp_crt_bundle_attach(&sHTTPS_ClientConfig.conf);
|
||||||
|
if(i32RetEmbedTLS != ESP_OK)
|
||||||
|
{
|
||||||
|
ESP_LOGE(TAG, "esp_crt_bundle_attach returned 0x%x\n\n", i32RetEmbedTLS);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if(i32RetEmbedTLS == ESP_OK)
|
|
||||||
{
|
|
||||||
//Setting up the SSL/TLS structure
|
|
||||||
i32RetEmbedTLS = mbedtls_ssl_config_defaults(&sHTTPS_ClientConfig.conf,
|
|
||||||
MBEDTLS_SSL_IS_CLIENT,
|
|
||||||
MBEDTLS_SSL_TRANSPORT_STREAM,
|
|
||||||
MBEDTLS_SSL_PRESET_DEFAULT);
|
|
||||||
|
|
||||||
if(i32RetEmbedTLS != ESP_OK)
|
if(i32RetEmbedTLS == ESP_OK)
|
||||||
{
|
{
|
||||||
ESP_LOGE(TAG, "mbedtls_ssl_config_defaults returned %d", i32RetEmbedTLS);
|
//Setting hostname for TLS session.
|
||||||
|
i32RetEmbedTLS = mbedtls_ssl_set_hostname(&sHTTPS_ClientConfig.ssl, CONFIG_OTA_HTTPS_SERVER_COMMON_NAME);
|
||||||
|
// Hostname set here should match CN in server certificate
|
||||||
|
if(i32RetEmbedTLS != ESP_OK)
|
||||||
|
{
|
||||||
|
ESP_LOGE(TAG, "mbedtls_ssl_set_hostname returned 0x%x", i32RetEmbedTLS);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if(i32RetEmbedTLS == ESP_OK)
|
if(i32RetEmbedTLS == ESP_OK)
|
||||||
{
|
|
||||||
mbedtls_ssl_conf_authmode(&sHTTPS_ClientConfig.conf, MBEDTLS_SSL_VERIFY_REQUIRED);
|
|
||||||
mbedtls_ssl_conf_ca_chain(&sHTTPS_ClientConfig.conf, &sHTTPS_ClientConfig.cacert, NULL);
|
|
||||||
mbedtls_ssl_conf_rng(&sHTTPS_ClientConfig.conf, mbedtls_ctr_drbg_random, &sHTTPS_ClientConfig.ctr_drbg);
|
|
||||||
|
|
||||||
i32RetEmbedTLS = mbedtls_ssl_setup(&sHTTPS_ClientConfig.ssl, &sHTTPS_ClientConfig.conf);
|
|
||||||
if(i32RetEmbedTLS != ESP_OK)
|
|
||||||
{
|
{
|
||||||
ESP_LOGE(TAG, "mbedtls_ssl_setup returned -0x%x\n\n", i32RetEmbedTLS);
|
//Setting up the SSL/TLS structure
|
||||||
|
i32RetEmbedTLS = mbedtls_ssl_config_defaults(&sHTTPS_ClientConfig.conf,
|
||||||
|
MBEDTLS_SSL_IS_CLIENT,
|
||||||
|
MBEDTLS_SSL_TRANSPORT_STREAM,
|
||||||
|
MBEDTLS_SSL_PRESET_DEFAULT);
|
||||||
|
|
||||||
|
if(i32RetEmbedTLS != ESP_OK)
|
||||||
|
{
|
||||||
|
ESP_LOGE(TAG, "mbedtls_ssl_config_defaults returned %d", i32RetEmbedTLS);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if(i32RetEmbedTLS == ESP_OK)
|
if(i32RetEmbedTLS == ESP_OK)
|
||||||
{
|
{
|
||||||
mbedtls_net_init(&sHTTPS_ClientConfig.server_fd);
|
mbedtls_ssl_conf_authmode(&sHTTPS_ClientConfig.conf, MBEDTLS_SSL_VERIFY_REQUIRED);
|
||||||
}
|
mbedtls_ssl_conf_ca_chain(&sHTTPS_ClientConfig.conf, &sHTTPS_ClientConfig.cacert, NULL);
|
||||||
|
mbedtls_ssl_conf_rng(&sHTTPS_ClientConfig.conf, mbedtls_ctr_drbg_random, &sHTTPS_ClientConfig.ctr_drbg);
|
||||||
|
|
||||||
|
i32RetEmbedTLS = mbedtls_ssl_setup(&sHTTPS_ClientConfig.ssl, &sHTTPS_ClientConfig.conf);
|
||||||
|
if(i32RetEmbedTLS != ESP_OK)
|
||||||
|
{
|
||||||
|
ESP_LOGE(TAG, "mbedtls_ssl_setup returned -0x%x\n\n", i32RetEmbedTLS);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(i32RetEmbedTLS == ESP_OK)
|
||||||
|
{
|
||||||
|
mbedtls_net_init(&sHTTPS_ClientConfig.server_fd);
|
||||||
|
}
|
||||||
|
|
||||||
if (i32RetEmbedTLS != ESP_OK)
|
if (i32RetEmbedTLS != ESP_OK)
|
||||||
{
|
{
|
||||||
i32RetHTTPClient = HTTPS_CLIENT_ERROR_INIT_EMBEDTLS;
|
i32RetHTTPClient = HTTPS_CLIENT_ERROR_INIT_EMBEDTLS;
|
||||||
}
|
}
|
||||||
|
|
||||||
return i32RetHTTPClient;
|
return i32RetHTTPClient;
|
||||||
}
|
}
|
||||||
|
@ -218,28 +219,28 @@ https_client_ret_t https_clientConnectToServer()
|
||||||
//Connecting to server
|
//Connecting to server
|
||||||
i32RetServerConnect = mbedtls_net_connect(&sHTTPS_ClientConfig.server_fd, CONFIG_OTA_HTTPS_SERVER_COMMON_NAME, CONFIG_OTA_HTTPS_SERVER_PORT, MBEDTLS_NET_PROTO_TCP);
|
i32RetServerConnect = mbedtls_net_connect(&sHTTPS_ClientConfig.server_fd, CONFIG_OTA_HTTPS_SERVER_COMMON_NAME, CONFIG_OTA_HTTPS_SERVER_PORT, MBEDTLS_NET_PROTO_TCP);
|
||||||
if (i32RetServerConnect != ESP_OK)
|
if (i32RetServerConnect != ESP_OK)
|
||||||
{
|
{
|
||||||
ESP_LOGE(TAG, "mbedtls_net_connect returned %x", i32RetServerConnect);
|
ESP_LOGE(TAG, "mbedtls_net_connect returned %x", i32RetServerConnect);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(i32RetServerConnect == ESP_OK)
|
if(i32RetServerConnect == ESP_OK)
|
||||||
{
|
|
||||||
mbedtls_ssl_set_bio(&sHTTPS_ClientConfig.ssl, &sHTTPS_ClientConfig.server_fd, mbedtls_net_send, mbedtls_net_recv, NULL);
|
|
||||||
|
|
||||||
//Performing the SSL/TLS handshake
|
|
||||||
while ((i32RetServerConnect = mbedtls_ssl_handshake(&sHTTPS_ClientConfig.ssl)) != 0)
|
|
||||||
{
|
{
|
||||||
if ((i32RetServerConnect != MBEDTLS_ERR_SSL_WANT_READ) && (i32RetServerConnect != MBEDTLS_ERR_SSL_WANT_WRITE))
|
mbedtls_ssl_set_bio(&sHTTPS_ClientConfig.ssl, &sHTTPS_ClientConfig.server_fd, mbedtls_net_send, mbedtls_net_recv, NULL);
|
||||||
{
|
|
||||||
ESP_LOGE(TAG, "mbedtls_ssl_handshake returned 0x%x", i32RetServerConnect);
|
//Performing the SSL/TLS handshake
|
||||||
}
|
while ((i32RetServerConnect = mbedtls_ssl_handshake(&sHTTPS_ClientConfig.ssl)) != 0)
|
||||||
|
{
|
||||||
|
if ((i32RetServerConnect != MBEDTLS_ERR_SSL_WANT_READ) && (i32RetServerConnect != MBEDTLS_ERR_SSL_WANT_WRITE))
|
||||||
|
{
|
||||||
|
ESP_LOGE(TAG, "mbedtls_ssl_handshake returned 0x%x", i32RetServerConnect);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if(i32RetServerConnect != ESP_OK)
|
if(i32RetServerConnect != ESP_OK)
|
||||||
{
|
{
|
||||||
i32RetHTTPClient = HTTPS_CLIENT_ERROR_INIT_CONNECT_TWO_SERVER;
|
i32RetHTTPClient = HTTPS_CLIENT_ERROR_INIT_CONNECT_TWO_SERVER;
|
||||||
}
|
}
|
||||||
return i32RetHTTPClient;
|
return i32RetHTTPClient;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -250,14 +251,14 @@ https_client_ret_t https_clientValidateServer()
|
||||||
|
|
||||||
//Verifying peer X.509 certificate
|
//Verifying peer X.509 certificate
|
||||||
if ((i32RetValidateServer = mbedtls_ssl_get_verify_result(&sHTTPS_ClientConfig.ssl)) != 0)
|
if ((i32RetValidateServer = mbedtls_ssl_get_verify_result(&sHTTPS_ClientConfig.ssl)) != 0)
|
||||||
{
|
{
|
||||||
ESP_LOGE(TAG, "Failed to verify peer certificate!");
|
ESP_LOGE(TAG, "Failed to verify peer certificate!");
|
||||||
}
|
}
|
||||||
|
|
||||||
if(i32RetValidateServer != ESP_OK)
|
if(i32RetValidateServer != ESP_OK)
|
||||||
{
|
{
|
||||||
i32RetHTTPClient = HTTPS_CLIENT_ERROR_INIT_VALIDATE_SERVER;
|
i32RetHTTPClient = HTTPS_CLIENT_ERROR_INIT_VALIDATE_SERVER;
|
||||||
}
|
}
|
||||||
return i32RetHTTPClient;
|
return i32RetHTTPClient;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -270,23 +271,25 @@ https_client_ret_t https_clientSendRequest()
|
||||||
|
|
||||||
//Writing HTTP request
|
//Writing HTTP request
|
||||||
while((u32WrittenBytes < strlen(REQUEST)) && bWrite)
|
while((u32WrittenBytes < strlen(REQUEST)) && bWrite)
|
||||||
{
|
|
||||||
i32RetSendRequest = mbedtls_ssl_write(&sHTTPS_ClientConfig.ssl,
|
|
||||||
(const unsigned char *)REQUEST + u32WrittenBytes,
|
|
||||||
strlen(REQUEST) - u32WrittenBytes);
|
|
||||||
if (i32RetSendRequest >= 0)
|
|
||||||
{
|
{
|
||||||
//bytes written
|
i32RetSendRequest = mbedtls_ssl_write(&sHTTPS_ClientConfig.ssl,
|
||||||
u32WrittenBytes += i32RetSendRequest;
|
(const unsigned char *)REQUEST + u32WrittenBytes,
|
||||||
} else if (i32RetSendRequest != MBEDTLS_ERR_SSL_WANT_WRITE && i32RetSendRequest != MBEDTLS_ERR_SSL_WANT_READ) {
|
strlen(REQUEST) - u32WrittenBytes);
|
||||||
ESP_LOGE(TAG, "mbedtls_ssl_write returned 0x%x", i32RetSendRequest);
|
if (i32RetSendRequest >= 0)
|
||||||
bWrite = false;
|
{
|
||||||
|
//bytes written
|
||||||
|
u32WrittenBytes += i32RetSendRequest;
|
||||||
|
}
|
||||||
|
else if (i32RetSendRequest != MBEDTLS_ERR_SSL_WANT_WRITE && i32RetSendRequest != MBEDTLS_ERR_SSL_WANT_READ)
|
||||||
|
{
|
||||||
|
ESP_LOGE(TAG, "mbedtls_ssl_write returned 0x%x", i32RetSendRequest);
|
||||||
|
bWrite = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if(bWrite == false)
|
if(bWrite == false)
|
||||||
{
|
{
|
||||||
i32RetHTTPClient = HTTPS_CLIENT_ERROR_INIT_SEND_REQUEST;
|
i32RetHTTPClient = HTTPS_CLIENT_ERROR_INIT_SEND_REQUEST;
|
||||||
}
|
}
|
||||||
return i32RetHTTPClient;
|
return i32RetHTTPClient;
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,30 +16,34 @@
|
||||||
#include "Mesh_network.h"
|
#include "Mesh_network.h"
|
||||||
|
|
||||||
#define ERASE_NVS //erase non volatile storage if full
|
#define ERASE_NVS //erase non volatile storage if full
|
||||||
|
#define QUEUE_NODES_SIZE 10
|
||||||
/*
|
#define QUEUE_MESSAGE_OTA_SIZE 10
|
||||||
enum ota_packet_type
|
#define SERVER_CHECK_INTERVAL 30 //in seconds
|
||||||
{
|
|
||||||
APP_Version_Request,
|
|
||||||
APP_Version_Response,
|
|
||||||
OTA_Data,
|
|
||||||
OTA_ACK,
|
|
||||||
OTA_Complete
|
|
||||||
};
|
|
||||||
*/
|
|
||||||
|
|
||||||
#define ERROR_CHECK(x) if (err == ESP_OK) \
|
#define ERROR_CHECK(x) if (err == ESP_OK) \
|
||||||
{ \
|
{ \
|
||||||
err = (x); \
|
err = (x); \
|
||||||
if (err != ESP_OK) \
|
if (err != ESP_OK) \
|
||||||
{ \
|
{ \
|
||||||
ESP_LOGE(LOG_TAG, "%s failed with error: 0x%x -> %s", #x, err, esp_err_to_name(err)); \
|
ESP_LOGE(LOG_TAG, "%s failed with error: 0x%x -> %s", #x, err, esp_err_to_name(err)); \
|
||||||
} \
|
} \
|
||||||
} \
|
} \
|
||||||
|
|
||||||
|
esp_err_t errMeshOTAInitialize();
|
||||||
|
|
||||||
|
//helper functions
|
||||||
bool bNewerVersion(const char* pu8Local, const char* pu8Remote);
|
bool bNewerVersion(const char* pu8Local, const char* pu8Remote);
|
||||||
esp_err_t errExtractVersionNumber(const char* pu8Data, uint32_t* pu32DataLenght, char* pc8RemoteVersionNumber);
|
esp_err_t errExtractVersionNumber(const char* pu8Data, uint32_t* pu32DataLenght, char* pc8RemoteVersionNumber);
|
||||||
esp_err_t errFindImageStart(const char* pu8Data, uint32_t* pu32DataLenght, uint32_t* pu32StartOffset);
|
esp_err_t errFindImageStart(const char* pu8Data, uint32_t* pu32DataLenght, uint32_t* pu32StartOffset);
|
||||||
|
|
||||||
|
//Handler
|
||||||
|
void vAddNodeToPossibleUpdatableQueue(uint8_t* pu8Data);
|
||||||
|
void vAddOTAControllMessageToQueue(MESH_PACKET_t* puMeshPacket);
|
||||||
|
void vChangeStateOfServerWorker(bool state);
|
||||||
|
|
||||||
|
//Tasks
|
||||||
|
void vTaskServerWorker(void *arg);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif /* H_MESH_OTA */
|
#endif /* H_MESH_OTA */
|
||||||
|
|
|
@ -59,6 +59,7 @@ struct meshPacket
|
||||||
OTA_Complete //signal end of image
|
OTA_Complete //signal end of image
|
||||||
} type;
|
} type;
|
||||||
uint8_t au8Payload[1024];
|
uint8_t au8Payload[1024];
|
||||||
|
mesh_addr_t meshSenderAddr;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct meshPacket MESH_PACKET_t;
|
typedef struct meshPacket MESH_PACKET_t;
|
||||||
|
@ -68,12 +69,18 @@ extern int32_t i32MeshLayer;
|
||||||
extern mesh_addr_t meshParentAddr;
|
extern mesh_addr_t meshParentAddr;
|
||||||
extern esp_netif_t* netif_sta;
|
extern esp_netif_t* netif_sta;
|
||||||
extern uint8_t u8ownMAC[6];
|
extern uint8_t u8ownMAC[6];
|
||||||
|
extern void (*pOTAChildConnectHandle)(uint8_t* );
|
||||||
|
extern void (*pChangeStateOfServerWorkerHandle)(bool );
|
||||||
|
|
||||||
esp_err_t errMeshNetworkInitialize();
|
esp_err_t errMeshNetworkInitialize();
|
||||||
esp_err_t errMeshNetworkInitializeWiFi();
|
esp_err_t errMeshNetworkInitializeWiFi();
|
||||||
esp_err_t errMeshNetworkInitializeRouter(mesh_cfg_t* cfg);
|
esp_err_t errMeshNetworkInitializeRouter(mesh_cfg_t* cfg);
|
||||||
|
|
||||||
esp_err_t errMeshNetworkSetAppReceiveHandle(void (*pFuncParam)(uint8_t * pu8Data, uint8_t* pu8Sender));
|
esp_err_t errMeshNetworkSetAppReceiveHandle(void (*pAppRxHandleTmp)(uint8_t * pu8Data, uint8_t* pu8Sender));
|
||||||
|
esp_err_t errMeshNetworkSetChildConnectedHandle(void (*pChildConnectHandleTmp)(uint8_t * pu8Data));
|
||||||
|
esp_err_t errMeshNetworkSetOTAMessageHandleHandle(void (*pOTAMessageHandleTmp)(MESH_PACKET_t* puMeshPacket));
|
||||||
|
|
||||||
|
esp_err_t errMeshNetworkSetChangeStateOfServerWorkerHandle(void (*pChangeStateOfServerWorkerHandleTmp)(bool bState));
|
||||||
|
|
||||||
bool bCheckMACEquality(uint8_t* pu8aMAC, uint8_t* pu8bMAC);
|
bool bCheckMACEquality(uint8_t* pu8aMAC, uint8_t* pu8bMAC);
|
||||||
void vGetOwnAddr(mesh_addr_t* pMeshOwnAddr);
|
void vGetOwnAddr(mesh_addr_t* pMeshOwnAddr);
|
||||||
|
|
12
main/Main.c
12
main/Main.c
|
@ -20,14 +20,18 @@ void app_main(void)
|
||||||
{
|
{
|
||||||
esp_err_t err = ESP_OK;
|
esp_err_t err = ESP_OK;
|
||||||
ESP_LOGI(LOG_TAG, "hardcoded: 0.0.1");
|
ESP_LOGI(LOG_TAG, "hardcoded: 0.0.1");
|
||||||
|
|
||||||
|
ESP_LOGI(LOG_TAG, "start mesh network");
|
||||||
err = errMeshNetworkInitialize();
|
err = errMeshNetworkInitialize();
|
||||||
ESP_ERROR_CHECK(err);
|
ESP_ERROR_CHECK(err);
|
||||||
|
|
||||||
//start ota
|
ESP_LOGI(LOG_TAG, "start ota");
|
||||||
|
err = errMeshOTAInitialize();
|
||||||
//start app
|
ESP_ERROR_CHECK(err);
|
||||||
errBlinkyLEDInitialize();
|
|
||||||
|
|
||||||
|
ESP_LOGI(LOG_TAG, "start app");
|
||||||
|
err = errBlinkyLEDInitialize();
|
||||||
|
ESP_ERROR_CHECK(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue