mwifi_root_read 和 mlink_httpd_read 的使用

XiotSamuel
Posts: 53
Joined: Sun Aug 29, 2021 1:50 pm

mwifi_root_read 和 mlink_httpd_read 的使用

Postby XiotSamuel » Tue Jan 18, 2022 6:35 am

我想問一下,如果我在ROOT NODE用了mlink_httpd_read 之後可以使用mwifi_root_read 嗎?

我在root node create 了這兩個task

Code: Select all

static void root_read_task(void *arg)
{
    mdf_err_t ret               = MDF_OK;
    mlink_httpd_t *httpd_data   = NULL;
    mwifi_data_type_t mwifi_type = {
        .compression = true,
        .communicate = MWIFI_COMMUNICATE_MULTICAST,
    };

    MDF_LOGI("root_read_task is running");

    while (esp_mesh_get_layer() == MESH_ROOT) {
        ret = mlink_httpd_read(&httpd_data, portMAX_DELAY);
        MDF_ERROR_GOTO(ret != MDF_OK || !httpd_data, FREE_MEM, "<%s> mwifi_root_read", mdf_err_to_name(ret));
        MDF_LOGD("Root send, addrs_num: %d, addrs_list: " MACSTR ", size: %d, data: %.*s",
                 httpd_data->addrs_num, MAC2STR(httpd_data->addrs_list),
                 httpd_data->size, httpd_data->size, httpd_data->data);

        mwifi_type.group = httpd_data->group;
        memcpy(&mwifi_type.custom, &httpd_data->type, sizeof(mlink_httpd_type_t));

        ret = mwifi_root_write(httpd_data->addrs_list, httpd_data->addrs_num,
                               &mwifi_type, httpd_data->data, httpd_data->size, true);
        MDF_ERROR_GOTO(ret != MDF_OK, FREE_MEM, "<%s> mwifi_root_write", mdf_err_to_name(ret));

 
FREE_MEM:

        if (httpd_data) {
            MDF_FREE(httpd_data->addrs_list);
            MDF_FREE(httpd_data->data);
            MDF_FREE(httpd_data);
        }
    }

    MDF_LOGW("root_read_task is exit");

    if (httpd_data) {
        MDF_FREE(httpd_data->addrs_list);
        MDF_FREE(httpd_data->data);
        MDF_FREE(httpd_data);
    }
    mesh_mqtt_stop();
    g_root_read_task_handle = NULL;
    vTaskDelete(NULL);

}

static void root_read_mwifi_task(void *arg)
{
    mdf_err_t ret = MDF_OK;
    char *data    = MDF_MALLOC(MWIFI_PAYLOAD_LEN);
    size_t size   = MWIFI_PAYLOAD_LEN;
    mwifi_data_type_t data_type      = {0};
    uint8_t src_addr[MWIFI_ADDR_LEN] = {0};

    MDF_LOGI("root_read_mwifi_task is running");

    while (mwifi_is_connected()) {
        size = MWIFI_PAYLOAD_LEN;
        memset(data, 0, MWIFI_PAYLOAD_LEN);
        ret = mwifi_root_read(src_addr, &data_type, data, &size, portMAX_DELAY);
        MDF_ERROR_CONTINUE(ret != MDF_OK, "<%s> mwifi_root_recv", mdf_err_to_name(ret));

        if (data_type.upgrade) { // This mesh package contains upgrade data.
            ret = mupgrade_root_handle(src_addr, data, size);
            MDF_ERROR_CONTINUE(ret != MDF_OK, "<%s> mupgrade_root_handle", mdf_err_to_name(ret));
        } else {
            MDF_LOGI("Receive [NODE] addr: " MACSTR ", size: %d, data: %s",
                     MAC2STR(src_addr), size, data);
        }
    }

    MDF_LOGW("root_read_mwifi_task is exit");
    g_root_read_mwifi_task_handle = NULL;
    MDF_FREE(data);
    vTaskDelete(NULL);
}
mwifi 便有 error message

Code: Select all

W (14299) [mwifi, 1401]: <buf error> Uncompress, size: 663
W (14531) [LIGHT_EXAMPLE, 198]: <MDF_ERR_BUF> mwifi_root_recv
求解。

ESP_Sunshine
Posts: 20
Joined: Wed May 19, 2021 12:48 pm

Re: mwifi_root_read 和 mlink_httpd_read 的使用

Postby ESP_Sunshine » Thu Mar 10, 2022 1:33 pm

mwifi_root_read 和 mlink_httpd_read 是可以同时使用的,你也可以看到 development_kit/light/main/light_example.c 里面例程使用。

看到你的这个错误是

Code: Select all

#define MDF_ERR_BUF                 0x10000D /**< The buffer is too small */
猜测可能是是你给的 size 太小导致的这个问题出现。

Who is online

Users browsing this forum: No registered users and 38 guests