espressif / esp-matter

Espressif's SDK for Matter
Apache License 2.0
619 stars 148 forks source link

Use Access Point along with Station Mode in ESP32 based Matter device (CON-1207) #969

Open bilalmalik76 opened 1 month ago

bilalmalik76 commented 1 month ago

Describe the question/query that you have We want to use access point mode along with station mode on an ESP32-based Matter device. Is this possible? If yes, can we simply use ESP-IDF Wi-Fi APIs to enable the access point, or are there any other APIs available in the ESP-Matter SDK?

dhrishi commented 1 month ago

We want to use access point mode along with station mode on an ESP32-based Matter device. Is this possible? If yes, can we simply use ESP-IDF Wi-Fi APIs to enable the access point,

Yes and yes. Make sure that you enable CONFIG_ESP_WIFI_SOFTAP_SUPPORT through the menuconfig and then use the SoftAP APIs

bilalmalik76 commented 1 month ago

@dhrishi Hi, we just need to enable this in defconfig CONFIG_ESP_WIFI_SOFTAP_SUPPORT=y and then we can normally use SoftAP APIs available in esp-idf right?

bilalmalik76 commented 1 month ago

@dhrishi Hi, I tried by add this CONFIG_ESP_WIFI_SOFTAP_SUPPORT=y in sdkconfig, But network management implmentation change its state from APSTA to STA. Please check this:

I (9741) wifi:mode : sta (80:65:99:c9:cd:94) + softAP (80:65:99:c9:cd:95) I (9741) wifi:enable tsf W (9751) wifi:Haven't to connect to a suitable AP now! I (9751) chip[DL]: Done driving station state, nothing else to do... I (9751) chip[DL]: WIFI_EVENT_AP_START I (9761) chip[DL]: WiFi AP state change: NotActive -> Active I (9761) chip[DL]: Changing ESP WiFi mode: STA+AP -> STA I (9771) wifi:mode : sta (80:65:99:c9:cd:94) I (9791) chip[DL]: WiFi AP state change: Active -> Deactivating I (9791) chip[DL]: WIFI_EVENT_STA_START W (9791) wifi:Haven't to connect to a suitable AP now! I (9801) chip[DL]: Done driving station state, nothing else to do... I (9801) chip[DL]: WIFI_EVENT_AP_STOP I (9801) chip[DL]: WiFi AP state change: Deactivating -> NotActive

shubhamdp commented 3 weeks ago

Can you check config options in menu (Top) → Component config → CHIP Device Layer → WiFi AP Options are enabled? If not please enable them and give a try.

shubhamdp commented 3 weeks ago

You will have to set the AP mode like this https://github.com/project-chip/connectedhomeip/blob/master/examples/platform/esp32/common/CHIPDeviceManager.cpp#L74-L75

What is your use case for soft-ap?

bilalmalik76 commented 3 weeks ago

@shubhamdp Actally it works with this, First set mode to AP and then enable it.

 CHIP_ERROR err_chip = chip::DeviceLayer::Internal::ESP32Utils::SetAPMode(true);
    if (err_chip != CHIP_NO_ERROR)
    {
        ESP_LOGE(TAG, "Failed to Set APMode");
    }

    ConnectivityMgr().SetWiFiAPMode(ConnectivityManager::kWiFiAPMode_Enabled);

But it sets the AP mode SSID and Password to default value and open, how can we change it SSID and use password instead of open?

shubhamdp commented 3 weeks ago

For now you will have to change it here: https://github.com/project-chip/connectedhomeip/blob/master/src/platform/ESP32/ConnectivityManagerImpl_WiFi.cpp#L948 or use the esp-idf raw APIs to perform what you want to do.

As the AP based commissioning mode is not supported in Matter hence its not really being maintained.

bilalmalik76 commented 3 weeks ago

Ok Thanks, we are not using AP mode for commissioning but to configure our device according to end user requirements with a web interface.

shubhamdp commented 2 weeks ago

Okay, If I understood correctly, then AP mode is only required when device is not commissioned.

bilalmalik76 commented 2 weeks ago

@shubhamdp we want to use AP mode anytime before or after commissioning.

jonsmirl commented 9 hours ago

You can implement custom Matter clusters to support any of your proprietary configuration needs. Doing it that way is secure.