esp-mesh-lite icon indicating copy to clipboard operation
esp-mesh-lite copied to clipboard

Non-Root Node Connects to ESP_Bridge Despite Custom softap_ssid Configuration (AEGHB-948)

Open mrjohannchang opened this issue 1 year ago • 1 comments

Checklist

  • [X] Checked the issue tracker for similar issues to ensure this is not a duplicate
  • [X] Read the documentation to confirm the issue is not addressed there and your configuration is set correctly
  • [X] Tested with the latest version to ensure the issue hasn't been fixed

How often does this bug occurs?

always

Expected behavior

A non-root node should not connect to ESP_Bridge when the softap_ssid in esp_mesh_lite_config_t is customized to a value other than ESP_Bridge.

Actual behavior (suspected bug)

When the softap_ssid in esp_mesh_lite_config_t is customized to MY_MESH_SSID, a non-root node still eventually connects to ESP_Bridge. This occurs when all potential parent nodes are unavailable, except for another node hosting ESP_Bridge.

Error logs or terminal output

No response

Steps to reproduce the behavior

I am testing multiple mesh networks in the same environment using this library. The issue arises under the following conditions:

The esp_mesh_lite_set_softap_ssid_to_nvs() and esp_mesh_lite_set_softap_psw_to_nvs() functions are not called on non-root nodes during testing. The esp_mesh_lite_erase_rtc_store() function has been called to clear any previously stored data. Despite the above setup and the softap_ssid being explicitly configured to MY_MESH_SSID, a non-root node eventually connects to ESP_Bridge when all potential parent nodes are unavailable, leaving only a node hosting ESP_Bridge.

This behavior undermines the ability to maintain separate mesh systems when multiple networks coexist in the same space.

Steps to Reproduce

  1. Configure the softap_ssid in esp_mesh_lite_config_t to a custom value, such as MY_MESH_SSID.
  2. Ensure that esp_mesh_lite_set_softap_ssid_to_nvs() and esp_mesh_lite_set_softap_psw_to_nvs() are not called.
  3. Call esp_mesh_lite_erase_rtc_store() to wipe any stored data on non-root nodes.
  4. Set up multiple mesh systems with overlapping coverage, ensuring some nodes are configured with ESP_Bridge.
  5. Observe the behavior of non-root nodes when parent nodes are unavailable.

Project release version

master branch

System architecture

ARM 64-bit (Apple M1/M2, Raspberry Pi 4/5)

Operating system

MacOS

Operating system version

15.1 (Sequoia)

Shell

ZSH

Additional context

static device_t const* device;
static bool initialized;

static void config_wifi_station(void) {
    wifi_config_t wifi_config = { 0 };

    if (device->is_base(device) || device->get_type(device) == DEVICE_TYPE_UNDEFINED) {
        char* ssid;
        char* pwd;
        size_t const ssid_len = config_get_wifi_sta_ssid(&ssid);
        size_t const pwd_len = config_get_wifi_sta_pass(&pwd);

        memcpy(wifi_config.sta.ssid, ssid, ssid_len);
        memcpy(wifi_config.sta.password, pwd, pwd_len);
    }
    ESP_ERROR_CHECK(esp_bridge_wifi_set_config(WIFI_IF_STA, &wifi_config));
}

static void config_wifi_mesh_lite(void) {
    wifi_config_t wifi_config = { 0 };
    char* ssid;
    char* pwd;
    size_t const ssid_len = config_get_wifi_mesh_ssid(&ssid);
    size_t const pwd_len = config_get_wifi_mesh_pass(&pwd);

    memcpy(wifi_config.ap.ssid, ssid, ssid_len);
    memcpy(wifi_config.ap.password, pwd, pwd_len);
    wifi_config.ap.ssid_hidden = false;

    ESP_ERROR_CHECK(esp_bridge_wifi_set_config(WIFI_IF_AP, &wifi_config));

    char softap_ssid[33] = { 0 };
    snprintf(softap_ssid, sizeof(softap_ssid), "%.32s", (char*)wifi_config.ap.ssid);

    esp_mesh_lite_config_t mesh_lite_config = ESP_MESH_LITE_DEFAULT_INIT();
    mesh_lite_config.mesh_id = config_get_mesh_id();
    mesh_lite_config.join_mesh_without_configured_wifi = !device->is_base(device);
    mesh_lite_config.softap_ssid = softap_ssid;
    mesh_lite_config.softap_password = (char*)wifi_config.ap.password;

    esp_mesh_lite_init(&mesh_lite_config);
}

uint8_t lumo_wifi_mesh_lite_get_level(void) { return initialized ? esp_mesh_lite_get_level() : 0; }

esp_err_t lumo_wifi_mesh_lite_init(device_t const* device_instance) {
    LUMO_LOGI("init start");

    device = device_instance;

    ESP_ERROR_CHECK(esp_netif_init());
    esp_bridge_create_all_netif();

    config_wifi_station();
    config_wifi_mesh_lite();

    if (device->is_base(device) || device->get_type(device) == DEVICE_TYPE_UNDEFINED) {
        RETURN_ON_ERROR(esp_mesh_lite_set_allowed_level(1), "Failed to set allowed level");
    } else {
        RETURN_ON_ERROR(esp_mesh_lite_set_disallowed_level(1), "Failed to set disallowed level");
    }

    esp_mesh_lite_start();

    ESP_ERROR_CHECK(lumo_mesh_comm_init());

    initialized = true;
    LUMO_LOGI("init end");
    return ESP_OK;
}

esp_err_t lumo_wifi_mesh_lite_deinit(void) {
    esp_err_t err = ESP_OK;

    if (!initialized) {
        err = ESP_ERR_INVALID_STATE;
        goto end;
    }

    initialized = false;

    err = esp_mesh_lite_disconnect();
    if (err != ESP_OK) { LUMO_LOGW("Failed to disconnect from mesh due to error %d", err); }

    err = esp_wifi_stop();
    if (err != ESP_OK) {
        LUMO_LOGE("Failed to stop Wi-Fi due to error %d", err);
        goto end;
    }

    err = esp_wifi_deinit();
    if (err != ESP_OK) {
        LUMO_LOGE("Failed to deinit Wi-Fi due to error %d", err);
        goto end;
    }

end:
    return err;
}

esp_err_t lumo_wifi_mesh_lite_erase_store(void) {
    esp_mesh_lite_erase_rtc_store();
    return ESP_OK;
}

(如果您偏好使用中文回覆也行!)

mrjohannchang avatar Jan 12 '25 22:01 mrjohannchang

选择父节点时并不会区分父节点和自己的 softap ssid 前缀是否相同。子节点判断是否加入某个父节点的条件是,匹配相同的 Mesh ID 以及匹配相同路由器信息。

tswen avatar Jan 20 '25 12:01 tswen