Skip to content

Comments

Add WIFI AP+STA Support#3374

Open
ayushsharma82 wants to merge 14 commits intoearlephilhower:masterfrom
ayushsharma82:ap-sta-support
Open

Add WIFI AP+STA Support#3374
ayushsharma82 wants to merge 14 commits intoearlephilhower:masterfrom
ayushsharma82:ap-sta-support

Conversation

@ayushsharma82
Copy link
Contributor

@earlephilhower This PR adds WiFi AP+STA support in arduino-pico SDK along with WIFIATSTA.ino example to test it.

Real world test done:

  • Pico connected to STA
  • Connected 2 phones to Pico's AP

Result: Success (all 3 connections are stable and work concurrently)

Copilot AI review requested due to automatic review settings February 11, 2026 22:11
// Only tear down STA side if it was running
if (_wifiHWInitted && !_apMode) {
_wifiHWInitted = false;
_wifi.end();

Check warning

Code scanning / CodeQL

Expression has no effect Warning

This expression has no effect (because
end
has no external side effects).
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 WiFiAPSTA example 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.

@ayushsharma82
Copy link
Contributor Author

Ready to merge captain.

@earlephilhower
Copy link
Owner

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 earlephilhower self-requested a review February 12, 2026 15:54
@ayushsharma82
Copy link
Contributor Author

@earlephilhower I tested this PR with NetWizard, although the core functionality is working again - there are a few minor quirks. For example WiFiClass disconnect and other small functions are not behaving same as ESP32. Upon calling disconnect the WiFiClass should only disconnect STA in WIFI_AP_STA mode...

I'll look into it more and add some commits today.

@ayushsharma82
Copy link
Contributor Author

@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.

Ref: https://github.com/espressif/arduino-esp32/tree/4e42521cf089e6dac9c9ff472ff15cc4be5b48bf/libraries/WiFi/src

@earlephilhower
Copy link
Owner

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.

@ayushsharma82
Copy link
Contributor Author

ayushsharma82 commented Feb 12, 2026

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.

@ayushsharma82
Copy link
Contributor Author

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 🚀 .

@earlephilhower
Copy link
Owner

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!).

@ayushsharma82
Copy link
Contributor Author

@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.

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

Successfully merging this pull request may close these issues.

2 participants