espressif / esp-mesh-lite

A lite version Wi-Fi Mesh, each node can access the network over the IP layer.
110 stars 15 forks source link

MESH-LITE-LAN-OTA,子节点升级失败,多种情况 (AEGHB-701) #100

Closed LYL14 closed 1 week ago

LYL14 commented 1 week ago

mesh组网后通过版本控制升级,新版本号大于当前版本升级 1.http升级版本号为11,当前所有节点版本号为10,根节点进行http-ota升级成功后(版本为11),子节点进行ota升级,子节点升级出现同时进行http-ota和mesh-lan-ota升级, (1)mesh-lan-ota升级进度100%后报错,http-ota继续进行升级为11。 (2)mesh-lan-ota升级成功后,子节点成功升级为版本10. 2.http升级版本号为11,当前所有节点版本号为10,子节点先进行升级,出现同时拉取http-ota和mesh-lan-ota,并且通过mesh-lan-ota升级成功,版本依然为10. 根节点和子节点升级任务代码如下:通过按键打开任务 `int now_version = get_current_version(); esp_err_t ota_finish_err = ESP_OK; esp_http_client_config_t config = { .url = "http://192.168.1.77:8888/s3-mesh-ota.bin", };

esp_https_ota_config_t ota_config = {
    .http_config = &config,
    .http_client_init_cb = _http_event_handler, // Register a callback to be invoked after esp_http_client is initialized
};

esp_https_ota_handle_t https_ota_handle = NULL;
esp_err_t err = esp_https_ota_begin(&ota_config, &https_ota_handle);
if (err != ESP_OK)
{
    ESP_LOGE(TAG, "ESP HTTPS OTA Begin failed");
    vTaskDelete(NULL);
}
esp_app_desc_t new_app_desc;
err = esp_https_ota_get_img_desc(https_ota_handle, &new_app_desc);
printf("11111111esp_https_ota_handle_t===%s\n", new_app_desc.version);

if (err != ESP_OK)
{
    printf("esp_https_ota_read_img_desc failed\n");
    ESP_LOGE(TAG, "esp_https_ota_read_img_desc failed");
    // esp_https_ota_abort(https_ota_handle);
    vTaskDelete(NULL);
}

if (atoi(new_app_desc.version) <= now_version)
{
    printf("new_app_desc.version) <= now_version\n");
    vTaskDelete(NULL);
}

// Root node, start the OTA process
if (esp_mesh_lite_get_level() > 1)
{
    /* Processing flow of child nodes. */
    int filesize = esp_https_ota_get_image_size(https_ota_handle);
    printf("esp_https_ota_get_image_size=%d\n", filesize);
    esp_mesh_lite_file_transmit_config_t transmit_config = {
        .type = ESP_MESH_LITE_OTA_TRANSMIT_FIRMWARE,
        .size = filesize,
        .extern_url_ota_cb = NULL,
    };
    esp_mesh_lite_transmit_file_start(&transmit_config);
}
else
{
    esp_mesh_lite_ota_notify_child_node_pause();
}

if (esp_mesh_lite_get_level() >= 1)
{
    while (1)
    {
        if (esp_mesh_lite_wait_ota_allow() != ESP_OK)
        {
            err = ESP_FAIL;
            break;
        }
        err = esp_https_ota_perform(https_ota_handle);
        if (err != ESP_ERR_HTTPS_OTA_IN_PROGRESS)
        {
            printf("--err-%0x\n", err);
            break;
        }
        int image_len_read = esp_https_ota_get_image_len_read(https_ota_handle);
        int total_size = esp_https_ota_get_image_size(https_ota_handle);
        float progress = (float)image_len_read / total_size * 100;
        ESP_LOGI(TAG, "OTA Progress: %.2f%%", progress);
        ESP_LOGD(TAG, "Image bytes read: %d", esp_https_ota_get_image_len_read(https_ota_handle));
    }
    if (err != ESP_OK)
    {
        printf(" esp_https_ota_perfo=%0x\n", err);
        esp_https_ota_abort(https_ota_handle);
        // vTaskDelete(NULL);
    }
}
printf("otaend/n");

ota_finish_err = esp_https_ota_finish(https_ota_handle);
if (ota_finish_err == ESP_OK)
{
    ESP_LOGI(TAG, "ESP_HTTPS_OTA upgrade successful. Rebooting ...");
    vTaskDelay(5000 / portTICK_PERIOD_MS);
    esp_restart();
}
else
{
    if (ota_finish_err == ESP_ERR_OTA_VALIDATE_FAILED)
    {
        ESP_LOGE(TAG, "Image validation failed, image is corrupted");
    }
    ESP_LOGE(TAG, "ESP_HTTPS_OTA upgrade failed 0x%x", ota_finish_err);
    // vTaskDelete(NULL);
}`
LYL14 commented 1 week ago

字节点mesh-lan-ota和http-ota,同时进行lan-ota失败日志 `I (265612) local_control: OTA Progress: 22.76% I (265642) local_control: OTA Progress: 22.86% I (265652) Mesh-Lite: LAN OTA Percentage: 100% I (265652) esp_image: segment 0: paddr=00210020 vaddr=3c0c0020 size=2c180h (180608) map I (265682) esp_image: segment 1: paddr=0023c1a8 vaddr=3fc98a00 size=03d5ch ( 15708) I (265682) esp_image: segment 2: paddr=0023ff0c vaddr=40374000 size=0010ch ( 268) I (265682) esp_image: segment 3: paddr=00240020 vaddr=42000020 size=b3ac4h (735940) map I (265792) esp_image: segment 4: paddr=002f3aec vaddr=4037410c size=1488ch ( 84108) E (265802) esp_image: Checksum failed. Calculated 0xf6 read 0x3c I (265802) esp_image: segment 0: paddr=00210020 vaddr=3c0c0020 size=2c180h (180608) map I (265832) esp_image: segment 1: paddr=0023c1a8 vaddr=3fc98a00 size=03d5ch ( 15708) I (265832) esp_image: segment 2: paddr=0023ff0c vaddr=40374000 size=0010ch ( 268) I (265842) esp_image: segment 3: paddr=00240020 vaddr=42000020 size=b3ac4h (735940) map I (265942) esp_image: segment 4: paddr=002f3aec vaddr=4037410c size=1488ch ( 84108) E (265952) esp_image: Checksum failed. Calculated 0xf6 read 0x3c E (265952) [ESP_Mesh_Lite_OTA]: esp_ota_set_boot_partition failed! err=0x1503 I (265962) [ESP_Mesh_Lite_OTA]: OTA End E (265962) Mesh-Lite: LAN OTA Fail! Reason: 7

I (265972) local_control: OTA Progress: 22.96% I (266042) local_control: OTA Progress: 23.06% I (266042) local_control: OTA Progress: 23.16% `