Add WIFI AP+STA Support#3374
Conversation
There was a problem hiding this comment.
Pull request overview
Adds concurrent WiFi AP+STA support for the CYW43 (Pico W / Pico 2 W) integration by separating lwIP netifs per interface and updating WiFi/AP plumbing, plus a new example sketch demonstrating dual-interface HTTP serving.
Changes:
- Add separate lwIP
netif*tracking for CYW43 STA vs AP and route CYW43 callbacks by interface (itf). - Update WiFi AP startup/teardown to support AP+STA via a second CYW43 lwIP instance and bind the DHCP server to a specific netif.
- Add
WiFiAPSTAexample sketch to exercise concurrent AP+STA operation.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| libraries/lwIP_CYW43/src/utility/CYW43shim.h | Track separate STA/AP netifs and expose interface index. |
| libraries/lwIP_CYW43/src/utility/CYW43shim.cpp | Implement per-interface netif lookup and AP vs STA begin/end behavior. |
| libraries/lwIP_CYW43/src/lwIP_CYW43.cpp | Remove redundant leave call so shutdown is handled in the shim. |
| libraries/WiFi/src/dhcpserver/dhcpserver.h | Extend DHCP init API to optionally bind to a specific lwIP netif. |
| libraries/WiFi/src/dhcpserver/dhcpserver.c | Bind DHCP server UDP PCB to a specific interface when provided. |
| libraries/WiFi/src/WiFiClass.h | Add AP+STA state tracking and AP-specific accessors in AP+STA mode. |
| libraries/WiFi/src/WiFiClass.cpp | Implement AP+STA start/stop using a second CYW43 instance and bind DHCP to AP netif. |
| libraries/WiFi/examples/WiFiAPSTA/WiFiAPSTA.ino | New example demonstrating concurrent STA connection + AP web server. |
| cores/rp2040/cyw43_wrappers.cpp | Route CYW43 callbacks to the correct lwIP netif by itf. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
|
Ready to merge captain. |
|
Very, very nice! 🚀 I could swear I tried it when the PicoW first came out and when the other virtual channel (what the driver uses to talk to the CYW34 firmware) was opened, the first one was closed. And at that point the driver and upper layer stack got very upset. So I hardcoded it on or off and didn't touch it... Give me a day or two to look this over, it's kind of busy here and not much coding time. |
|
@earlephilhower I tested this PR with NetWizard, although the core functionality is working again - there are a few minor quirks. For example WiFiClass I'll look into it more and add some commits today. |
|
@earlephilhower Shall I split the WiFiClass into WiFiSTA and WiFiAP as seen in arduino-esp32 SDK? That pretty much makes more sense and has better separation of logic. |
|
If it doesn't break compatibility and it doesn't turn into a massive mess, that would be fine. I have a feeling it would be kind of a pain, but it's been a while since I wrote the stuff so maybe I'm just scared of opening up something that works. 😆 FWIW, the WiFiClass here was based on the Arduino 'WiFi' API with ESP compatibility hacks so it may not be as simple as separating things and then moving WiFi STA/AP to WiFiSTA/AP and have a dummy top-level class inherit both. |
|
Looks like Arduino WiFi API was never intended to even have an "AP" mode. ESP32 style API is far more superior in that case. I can maintain backwards compatibility with existing functions but there is one thing - All the 'AP' related code has to go into their own "softAPXXXX" functions (just like ESP32 WiFi API) for better separation at some point in future. If I go around doing it, I'll open a separate PR which you can merge when you are ready to add breaking changes. |
|
Done with the changes and ready to merge. I think this PR has reached a point now which should be good enough for arduino-pico v5. Whenever its time to add breaking changes, I'll suggest copying the ESP32 WiFiSTA and WiFiAP classes and porting CYW43 driver to it. ESP8266 platform is end-of-life and we should deprecate the old logic and move arduino-pico's WiFi API to use latest and proven ESP32 WiFi APIs. Also tested with NetWizard, everything works flawlessly 🚀 . |
|
Awesome. This past week was crazy hectic and I didn't get a chance to look at this. I'll pencil it some time this coming weekend to give it a once-over and see that it doesn't break any of the existing examples (probably not, but it's easy to test!). |
|
@earlephilhower No worries. As a solo-maintainer myself of multiple repositories I can understand the situation. Let me know if anything comes up in the testing this weekend. |
@earlephilhower This PR adds WiFi AP+STA support in arduino-pico SDK along with
WIFIATSTA.inoexample to test it.Real world test done:
Result: Success (all 3 connections are stable and work concurrently)