fn check app version
This commit is contained in:
114
main/mesh_main.c
114
main/mesh_main.c
@ -40,8 +40,6 @@ struct ota_mesh_packet {
|
||||
uint8_t au8Payload[1024];
|
||||
};
|
||||
|
||||
|
||||
|
||||
/*******************************************************
|
||||
* Function Declarations
|
||||
*******************************************************/
|
||||
@ -52,7 +50,6 @@ esp_err_t esp_mesh_send_packet(mesh_addr_t* dest, struct ota_mesh_packet* packet
|
||||
* Function Definitions
|
||||
*******************************************************/
|
||||
|
||||
|
||||
esp_err_t esp_mesh_ota_send(mesh_addr_t* dest)
|
||||
{
|
||||
esp_err_t err = ESP_OK;
|
||||
@ -157,8 +154,6 @@ esp_err_t esp_mesh_ota_receive(mesh_addr_t* dest, struct ota_mesh_packet* packet
|
||||
return err;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//returns true if MAC address is equal
|
||||
bool esp_mesh_check_MAC_Equality(uint8_t* aMAC, uint8_t* bMAC)
|
||||
{
|
||||
@ -480,10 +475,62 @@ void ip_event_handler(void *arg, esp_event_base_t event_base,
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 999.999.999
|
||||
* Return true if remote version is newer (higher) than local version
|
||||
*/
|
||||
bool bNewerVersion(const char* pu8Local, const char* pu8Remote){
|
||||
|
||||
ESP_LOGI(MESH_TAG, "Local %s", pu8Local);
|
||||
ESP_LOGI(MESH_TAG, "Remote %s", pu8Remote);
|
||||
|
||||
char u8LocalTmp[12];
|
||||
char u8RemoteTmp[12];
|
||||
|
||||
char* pu8saveptrLocal;
|
||||
char* pu8saveptrRemote;
|
||||
|
||||
strcpy(u8LocalTmp, pu8Local);
|
||||
strcpy(u8RemoteTmp, pu8Remote);
|
||||
|
||||
char* pu8TokenLocal = strtok_r(u8LocalTmp, ".", &pu8saveptr1);
|
||||
char* pu8TokenRemote = strtok_r(u8RemoteTmp, ".", &saveptr2) ;
|
||||
|
||||
|
||||
bool bReturn = false;
|
||||
|
||||
uint8_t u8Index = 0;
|
||||
|
||||
while( (u8Index <= 2) && (bReturn == false){
|
||||
|
||||
u8Index++;
|
||||
|
||||
printf("loop: %i\n", u8Index);
|
||||
|
||||
printf("tokenLocal: %s\n", pu8TokenLocal);
|
||||
printf("tokenRemote: %s\n", pu8TokenRemote);
|
||||
|
||||
if(atoi(pu8TokenLocal) < atoi(pu8TokenRemote))
|
||||
{
|
||||
bReturn = true;
|
||||
}
|
||||
|
||||
pu8TokenLocal = strtok_r(NULL, ".", &pu8saveptr1);
|
||||
pu8TokenRemote = strtok_r(NULL, ".", &saveptr2) ;
|
||||
}
|
||||
|
||||
return bReturn;
|
||||
}
|
||||
|
||||
|
||||
void app_main(void)
|
||||
{
|
||||
|
||||
esp_err_t err;
|
||||
|
||||
/*
|
||||
esp_err_t err;
|
||||
|
||||
|
||||
err = nvs_flash_erase();
|
||||
|
||||
@ -503,7 +550,27 @@ void app_main(void)
|
||||
ESP_LOGI(MESH_TAG, "Start address: %d", (*currentPartition).address);
|
||||
ESP_LOGI(MESH_TAG, "Size: %d", (*currentPartition).size); //passt
|
||||
ESP_LOGI(MESH_TAG, "Encrypted: %d", (*currentPartition).encrypted);
|
||||
|
||||
|
||||
esp_app_desc_t curPartitionDesc;
|
||||
err = esp_ota_get_partition_description(currentPartition, &curPartitionDesc);
|
||||
ESP_ERROR_CHECK(err);
|
||||
ESP_LOGI(MESH_TAG, "currentPartition project_name: %s", (curPartitionDesc).project_name);
|
||||
ESP_LOGI(MESH_TAG, "currentPartition version: %s", (curPartitionDesc).version);
|
||||
ESP_LOGI(MESH_TAG, "currentPartition Timestamp: %s %s", (curPartitionDesc).date, (curPartitionDesc).time);
|
||||
|
||||
char test[] = "1.2.3";
|
||||
|
||||
|
||||
if(bNewerVersion((curPartitionDesc).version, test)){
|
||||
|
||||
ESP_LOGI(MESH_TAG, "Newer Version available");
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/* tcpip initialization */
|
||||
ESP_ERROR_CHECK(esp_netif_init());
|
||||
|
||||
@ -566,41 +633,12 @@ void app_main(void)
|
||||
esp_mesh_is_root_fixed() ? "root fixed" : "root not fixed",
|
||||
esp_mesh_get_topology(), esp_mesh_get_topology() ? "(chain)":"(tree)", esp_mesh_is_ps_enabled());
|
||||
|
||||
|
||||
/* START OTA MESH */
|
||||
|
||||
//if (esp_mesh_is_root()) {
|
||||
ESP_LOGI(MESH_TAG, "ROOT NODE");
|
||||
//https ota
|
||||
|
||||
// while(1){
|
||||
for(;;) {
|
||||
if(gpio_get_level(0) == 0){
|
||||
break;
|
||||
}
|
||||
vTaskDelay(1000 / portTICK_PERIOD_MS);
|
||||
}
|
||||
|
||||
mesh_addr_t children[CONFIG_MESH_ROUTE_TABLE_SIZE];
|
||||
uint16_t u16ChildrenSize;
|
||||
esp_mesh_get_Children(children, &u16ChildrenSize);
|
||||
|
||||
ESP_LOGI(MESH_TAG, "ChildrenSize: %i", u16ChildrenSize);
|
||||
|
||||
|
||||
struct ota_mesh_packet packet;
|
||||
|
||||
packet.type=APP_Version_Request;
|
||||
//packet.au8Payload[0] = 42;
|
||||
|
||||
for (uint16_t i = 0; i < u16ChildrenSize; i++)
|
||||
{
|
||||
ESP_ERROR_CHECK (esp_mesh_send_packet(&children[i], &packet));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// }//end while 1
|
||||
//} // end root node
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user