arduino-esp32 icon indicating copy to clipboard operation
arduino-esp32 copied to clipboard

Arduino WiFi AP API coexistence with esp-matter ConnectivityManager Implementation

Open HamzaHajeir opened this issue 1 year ago • 8 comments

Board

ESP32-S3-DevKitC-1-N8R2

Device Description

.

Hardware Configuration

..

Version

v3.0.4

IDE Name

PlatformIO

Operating System

Windows 11

Flash frequency

80MHz

PSRAM enabled

yes

Upload speed

.

Description

I'm building a custom project which coexists esp-matter and Arduino in one project.

Such that the WiFi management is went through Arduino library (WiFi), and to inform CHIP's core that the application controls the WiFi. through:

auto &connMgr = chip::DeviceLayer::ConnectivityMgrImpl();
connMgr.SetWiFiStationMode(chip::DeviceLayer::ConnectivityManager::WiFiStationMode::kWiFiStationMode_ApplicationControlled);
connMgr.SetWiFiAPMode(chip::DeviceLayer::ConnectivityManager::WiFiAPMode::kWiFiAPMode_ApplicationControlled);

All up to here is okay, but when engaging with WiFi.enableAP(true) API an error happens, which is a result of incompatibility with esp-matter's code regarding WiFi.

Both stacks initializes the netif`'s (Arduino)(esp-matter[1][2]). While there should be exactly one netif initialized, the program crashes in the second call of.

A suggestion of using the name keys, and the same pattern of code in esp-matter's start(), such that to ask for the netif by name, and if not existed to create it:

      if ((esp_netifs[ESP_IF_WIFI_AP] = esp_netif_get_handle_from_ifkey("WIFI_AP_DEF")) == NULL) {
        esp_netifs[ESP_IF_WIFI_AP] = esp_netif_create_default_wifi_ap();
      }
      if ((esp_netifs[ESP_IF_WIFI_STA] = esp_netif_get_handle_from_ifkey("WIFI_STA_DEF")) == NULL) {
        esp_netifs[ESP_IF_WIFI_STA] = esp_netif_create_default_wifi_sta();
      }

Which worked well in my setup.

Sketch

.

Debug Message

E (4666) esp_netif_lwip: esp_netif_new_api: Failed to configure netif with config=0x3fccabf0 (config or if_key is NULL or duplicate key)

Other Steps to Reproduce

No response

I have checked existing issues, online documentation and the Troubleshooting Guide

  • [x] I confirm I have checked existing issues, online documentation and Troubleshooting guide.

HamzaHajeir avatar Sep 30 '24 14:09 HamzaHajeir

you are a bit ahead of the curve here. We do not guarantee that this will ever work, because matter manages WiFi on it's own. Meaning interfaces, events and so on. Let's wait for the work that will be done for v3.1 first

me-no-dev avatar Sep 30 '24 15:09 me-no-dev

you are a bit ahead of the curve here. We do not guarantee that this will ever work, because matter manages WiFi on it's own. Meaning interfaces, events and so on. Let's wait for the work that will be done for v3.1 first

I see that point, but its management of WiFi is overridable by the code I pasted.

What's not so following is esp_matter library which does not check against the mode in its interference. Seems its interference stops at esp_matter::start()

HamzaHajeir avatar Sep 30 '24 16:09 HamzaHajeir

We do not guarantee that this will ever work

No more to say currently. Imho at some point it makes no sense to use Arduino only. Matter can be used when building Arduino as an component of IDF. With pioarduino it is very easy to do.

Jason2866 avatar Oct 01 '24 09:10 Jason2866

The good news that I've a primarily working code that coexists between esp-matter and arduino.

The provided fix/enhancement is the only primary issue I've met.

Other issue appeared because of CONFIG_LWIP_TCPIP_CORE_LOCKING -and- CONFIG_LWIP_CHECK_THREAD_SAFETY checks exposed them. I'll provide a fix regarding that for AsyncUDP.cpp that calls raw LwIP APIs without performing any locking. The fix will help primarily arduino-as-a-idf-component users

Until https://github.com/espressif/esp32-arduino-lib-builder/pull/186 gets merged (and ofcourse the fix), direct Arduino users will be helped with.

HamzaHajeir avatar Oct 01 '24 10:10 HamzaHajeir

The close was most probably a misclick.

HamzaHajeir avatar Oct 02 '24 14:10 HamzaHajeir

@HamzaHajeir - Please review this issue given the current Arduino Matter Library. #7432 https://github.com/espressif/arduino-esp32/tree/master/libraries/Matter

At this time, Matter relies on Arduino WiFi Library for connectivity.

There is a Matter example that uses WiFi AP or BLE for provissioning the WiFi Network using WiFi Prov Library. https://github.com/espressif/arduino-esp32/blob/master/libraries/Matter/examples/WiFiProvWithinMatter/WiFiProvWithinMatter.ino

Let me know if we can consider this issue solved.

SuGlider avatar Feb 13 '25 14:02 SuGlider

Hi Rodrigo,

I have just returned from a work trip that elapsed over a month, I'll be studying this issue again with the newest implementations at soonest and feedback subsequently.

With best, Hamza

‫في الخميس، 13 فبراير 2025 في 5:14 م تمت كتابة ما يلي بواسطة ‪Rodrigo Garcia‬‏ @.***‬‏>:‬

@HamzaHajeir https://github.com/HamzaHajeir - Please review this issue given the current Arduino Matter Library. #7432 https://github.com/espressif/arduino-esp32/issues/7432 https://github.com/espressif/arduino-esp32/tree/master/libraries/Matter

At this time, Matter relies on Arduino WiFi Library for connectivity.

There is a Matter example that uses WiFi AP or BLE for provissioning the WiFi Network using WiFi Prov Library.

https://github.com/espressif/arduino-esp32/blob/master/libraries/Matter/examples/WiFiProvWithinMatter/WiFiProvWithinMatter.ino

Let me know if we can consider this issue solved.

— Reply to this email directly, view it on GitHub https://github.com/espressif/arduino-esp32/issues/10391#issuecomment-2656722900, or unsubscribe https://github.com/notifications/unsubscribe-auth/AH3O7J4BNBYHLD5YV2RVG732PSSCVAVCNFSM6AAAAABPDNVOLCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDMNJWG4ZDEOJQGA . You are receiving this because you were mentioned.Message ID: @.***> [image: SuGlider]SuGlider left a comment (espressif/arduino-esp32#10391) https://github.com/espressif/arduino-esp32/issues/10391#issuecomment-2656722900

@HamzaHajeir https://github.com/HamzaHajeir - Please review this issue given the current Arduino Matter Library. #7432 https://github.com/espressif/arduino-esp32/issues/7432 https://github.com/espressif/arduino-esp32/tree/master/libraries/Matter

At this time, Matter relies on Arduino WiFi Library for connectivity.

There is a Matter example that uses WiFi AP or BLE for provissioning the WiFi Network using WiFi Prov Library.

https://github.com/espressif/arduino-esp32/blob/master/libraries/Matter/examples/WiFiProvWithinMatter/WiFiProvWithinMatter.ino

Let me know if we can consider this issue solved.

— Reply to this email directly, view it on GitHub https://github.com/espressif/arduino-esp32/issues/10391#issuecomment-2656722900, or unsubscribe https://github.com/notifications/unsubscribe-auth/AH3O7J4BNBYHLD5YV2RVG732PSSCVAVCNFSM6AAAAABPDNVOLCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDMNJWG4ZDEOJQGA . You are receiving this because you were mentioned.Message ID: @.***>

HamzaHajeir avatar Feb 14 '25 16:02 HamzaHajeir

Hi @SuGlider, I've done a primary review of the issue, and I am not sure why it's not appearing at your example, as CHIP_DEVICE_CONFIG_ENABLE_WIFI is defined by default (As CHIP_DEVICE_CONFIG_ENABLE_WIFI_STATION is defaulted to y -> [1] -> [2]).

Therefore both Arduino WiFi and CHIP's calls esp_netif_create_default_wifi_ap()/esp_netif_create_default_wifi_sta(), with a difference that Arduino does not check for an existent one, which I added in my post.

CHIP's one adds the necessary guards to prevent duplicate call when it becomes second.

What I see that adding these guards is the wise decision - anyway -, what do you think?

BTW: I'm not sure why not adding kWiFiStationMode_ApplicationControlled would make your example/library stable, as the CHIP also reacts to the network events if not.

HamzaHajeir avatar Mar 05 '25 14:03 HamzaHajeir