An ESP32 WLAN cannot use both a STA and an AP simultaneously. #18473
-
|
The following code will reproduce the problem: import network
wlan = network.WLAN()
wlan.active(True)
ap = network.WLAN(network.WLAN.IF_AP)
ap.config(ssid='ESP-AP')
|
Beta Was this translation helpful? Give feedback.
Answered by
shariltumin
Nov 25, 2025
Replies: 2 comments
-
|
By modifying the source code, both STA and AP can be used simultaneously. diff --git a/m5stack/network_wlan.c b/m5stack/network_wlan.c
index 42b2f1a7..520935f6 100644
--- a/m5stack/network_wlan.c
+++ b/m5stack/network_wlan.c
@@ -238,6 +238,7 @@ void esp_initialise_wifi(void) {
#endif
ESP_LOGD("modnetwork", "Initializing WiFi");
esp_exceptions(esp_wifi_init(&cfg));
+ esp_exceptions(esp_wifi_set_mode(WIFI_MODE_APSTA));
esp_exceptions(esp_wifi_set_storage(WIFI_STORAGE_RAM));
ESP_LOGD("modnetwork", "Initialized");
@@ -281,7 +282,7 @@ static mp_obj_t network_wlan_active(size_t n_args, const mp_obj_t *args) {
wifi_started = false;
}
} else {
- esp_exceptions(esp_wifi_set_mode(mode));
+ // esp_exceptions(esp_wifi_set_mode(mode));
if (!wifi_started) {
esp_exceptions(esp_wifi_start()); |
Beta Was this translation helpful? Give feedback.
0 replies
-
|
I don't think it's necessary to modify the "network_wlan.c" code to enable both STA and AP simultaneously. All you need to do is the following: import network
from time import sleep
STI, STK = "wifi-234", "KeyMeIn123" # your Wifi cred
API, APK = "my_ap_id", "my_ap_pwd" # what your AP looks like
APIP = ('10.10.6.1', '255.255.255.0', '10.10.6.1', '10.10.6.255') # your AP network
# Station
sta = network.WLAN(network.STA_IF)
sta.active(True)
sta.connect(STI, STK)
while (sta.isconnected() == False):
print('Sta not ready!')
sleep(1)
else:
print('Connected to external Wi-Fi with IP:', sta.ifconfig()[0])
# Access point
ap = network.WLAN(network.AP_IF)
ap.active(True)
ap.config(essid=API, password=APK, authmode=3)
ap.ifconfig(APIP)
print("AP mode active with IP:", ap.ifconfig()[0]) |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
lbuque
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment

I don't think it's necessary to modify the "network_wlan.c" code to enable both STA and AP simultaneously. All you need to do is the following: