Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
3 tasks done
mrjohannchang opened this issue Jan 12, 2025 · 1 comment

Comments

@mrjohannchang
Copy link

mrjohannchang commented Jan 12, 2025

Checklist

  • Checked the issue tracker for similar issues to ensure this is not a duplicate
  • Read the documentation to confirm the issue is not addressed there and your configuration is set correctly
  • 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;
}

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

@github-actions github-actions bot changed the title Non-Root Node Connects to ESP_Bridge Despite Custom softap_ssid Configuration Non-Root Node Connects to ESP_Bridge Despite Custom softap_ssid Configuration (AEGHB-948) Jan 12, 2025
@tswen
Copy link
Contributor

tswen commented Jan 20, 2025

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants