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

Arduino WiFi AP API coexistence with esp-matter ConnectivityManager Implementation #10391

Open
1 task done
HamzaHajeir opened this issue Sep 30, 2024 · 8 comments
Open
1 task done
Assignees
Labels
Status: Solved Type: Feature request Feature request for Arduino ESP32
Milestone

Comments

@HamzaHajeir
Copy link
Contributor

HamzaHajeir commented Sep 30, 2024

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

  • I confirm I have checked existing issues, online documentation and Troubleshooting guide.
@HamzaHajeir HamzaHajeir added the Status: Awaiting triage Issue is waiting for triage label Sep 30, 2024
@me-no-dev
Copy link
Member

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

@HamzaHajeir
Copy link
Contributor Author

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()

@Jason2866
Copy link
Collaborator

Jason2866 commented Oct 1, 2024

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.

@HamzaHajeir
Copy link
Contributor Author

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 espressif/esp32-arduino-lib-builder#186 gets merged (and ofcourse the fix), direct Arduino users will be helped with.

@SuGlider SuGlider changed the title Arduino WiFi coexistence with esp-matter Arduino WiFi AP API coexistence with esp-matter ConnectivityManager Implementation Oct 2, 2024
@SuGlider SuGlider added Type: Feature request Feature request for Arduino ESP32 and removed Status: Awaiting triage Issue is waiting for triage labels Oct 2, 2024
@SuGlider SuGlider added this to the 3.2.0 milestone Oct 2, 2024
@SuGlider SuGlider self-assigned this Oct 2, 2024
@HamzaHajeir HamzaHajeir reopened this Oct 2, 2024
@HamzaHajeir
Copy link
Contributor Author

The close was most probably a misclick.

@SuGlider
Copy link
Collaborator

@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 SuGlider moved this from Todo to In Progress in Arduino ESP32 Core Project Roadmap Feb 13, 2025
@HamzaHajeir
Copy link
Contributor Author

HamzaHajeir commented Feb 14, 2025 via email

@HamzaHajeir
Copy link
Contributor Author

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.

@Parsaabasi Parsaabasi modified the milestones: 3.2.0, 3.3.0 Mar 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Solved Type: Feature request Feature request for Arduino ESP32
Projects
Status: In Progress
Development

No branches or pull requests

5 participants