STA_IF and AP_IF at the same time, traffic routing #14270
-
I have a situation where I'd like an ESP32 to be running in AP-mode so that I can connect to several ESP32's in STA-mode AND then run on STA-mode to connect to another AP. I found this discussion: The part I am struggling-with is ... how do I route the traffic from one interface to the other when it is connected to both interfaces? Would I need to assign static IPs or use ESP-Now? Edit: Connect to both, but both are not active at the same time?? Thanks. |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 6 replies
-
Only IP-Forward is working currently. Here what I tried: """
https://github.com/micropython/micropython/issues/7699
I compiled the firmware by myself, because CONFIG_LWIP_IP_FORWARD and CONFIG_LWIP_IPV4_NAPT is not enabled by default.
IP-Forwarding works, but NAT doesn't work. I guess you have to call a C function,
to activate NAT on the client interface, but this function is not exposed to micropython.
Afik a C module must expose this function to python land.
Modified sdkconfig.board
========================
CONFIG_LWIP_IP_FORWARD=y
CONFIG_LWIP_IPV4_NAPT=y
"""
from time import sleep_ms
from network import WLAN, AUTH_WPA3_PSK, AUTH_WPA2_PSK, STA_IF, AP_IF, hostname, country
country("DE")
hostname("My awsome ESP32S3")
client = WLAN(STA_IF)
server = WLAN(AP_IF)
client.active(False)
server.active(False)
client.active(True)
server.active(True)
client.connect("SSID", "PSKPSK")
server.config(ssid="ESP32S3", key="1234567890", security=AUTH_WPA3_PSK)
while client.ifconfig()[0] == "0.0.0.0":
print(".", end="")
sleep_ms(100)
print()
print("Connected to Wifi")
print(client.ifconfig())
dns = client.ifconfig()[-1]
ip = "192.168.10.1"
mask = "255.255.255.0"
server.ifconfig((ip, mask, ip, dns)) |
Beta Was this translation helpful? Give feedback.
-
Hi Dave, Are you still interested in the possibility of running AP+STA on the ESP32 at the same time? I have a sample script that does just that. The script is running on an ESP32, both AP and STA network are enabled, AP will listen for WIFI client request, I use an old smartphone as client here. STA will connect to my home network through my Wifi router. The script starts two TCP servers listening on port 23, one bound to the AP IP address and the other bound to the STA IP address. Using the smartphone, I connect to the AP and launch a telnet client application to connect to the AP's IP address. Then on my Linux PC, I start a telnet session to the IP address of the STA. The idea is to send text messages between these two telnet clients using the ESP32 as a bridge. The test script is at https://github.com/shariltumin/bit-and-pieces/blob/main/telnet-bridge/telnet_bridge.py The script needs more work to be useful, it is just a proof of concept. The run log below shows that we can run AP+STA on ESP32 at the same time. Remount local directory ./ at /remote
>>> import telnet_bridge
>>> telnet_bridge.main()
AP mode active with IP: 10.10.4.1
Connected to external Wi-Fi with IP: 192.168.4.92
AP: 10.10.4.1 STA: 192.168.4.92
Telnet server started on 10.10.4.1:23, waiting for a client...
Client connected from ('10.10.4.2', 42582)
Telnet server started on 192.168.4.92:23, waiting for a client...
Client connected from ('192.168.4.27', 45704)
Forwarded data from AP client to STA client
Forwarded data from AP client to STA client
Forwarded data from STA client to AP client
Forwarded data from AP client to STA client
Forwarded data from STA client to AP client
Forwarded data from AP client to STA client
Forwarded data from AP client to STA client
AP client disconnected
>>> |
Beta Was this translation helpful? Give feedback.
-
Hi shariltumin, Can you help me in setting up captive portal in psoc 6 mcu?
…On Tue, 10 Sep 2024 at 7:00 PM, shariltumin ***@***.***> wrote:
Hi Dave, Are you still interested in the possibility of running AP+STA on
the ESP32 at the same time? I have a sample script that does just that.
The script is running on an ESP32, both AP and STA network are enabled, AP
will listen for WIFI client request, I use an old smartphone as client
here. STA will connect to my home network through my Wifi router.
The script starts two TCP servers listening on port 23, one bound to the
AP IP address and the other bound to the STA IP address.
Using the smartphone, I connect to the AP and launch a telnet client
application to connect to the AP's IP address. Then on my Linux PC, I start
a telnet session to the IP address of the STA. The idea is to send text
messages between these two telnet clients using the ESP32 as a bridge.
The test script is at
https://github.com/shariltumin/bit-and-pieces/blob/main/telnet-bridge/telnet_bridge.py
The script needs more work to be useful, it is just a proof of concept.
The run log below shows that we can run AP+STA on ESP32 at the same time.
Remount local directory ./ at /remote
>>> import telnet_bridge
>>> telnet_bridge.main()
AP mode active with IP: 10.10.4.1
Connected to external Wi-Fi with IP: 192.168.4.92
AP: 10.10.4.1 STA: 192.168.4.92
Telnet server started on 10.10.4.1:23, waiting for a client...
Client connected from ('10.10.4.2', 42582)
Telnet server started on 192.168.4.92:23, waiting for a client...
Client connected from ('192.168.4.27', 45704)
Forwarded data from AP client to STA client
Forwarded data from AP client to STA client
Forwarded data from STA client to AP client
Forwarded data from AP client to STA client
Forwarded data from STA client to AP client
Forwarded data from AP client to STA client
Forwarded data from AP client to STA client
AP client disconnected
>>>
—
Reply to this email directly, view it on GitHub
<#14270 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/BF3AKKG4YCMNTMG6KYZJMHLZV3X63AVCNFSM6AAAAABF5ZSKFWVHI2DSMVQWIX3LMV43URDJONRXK43TNFXW4Q3PNVWWK3TUHMYTANRQGI3TEOA>
.
You are receiving this because you commented.Message ID:
***@***.***
com>
|
Beta Was this translation helpful? Give feedback.
-
Is there any proper way to bridge WLAN to USB RNDIS? I use this patch: #16459 |
Beta Was this translation helpful? Give feedback.
Hi Dave, Are you still interested in the possibility of running AP+STA on the ESP32 at the same time? I have a sample script that does just that.
The script is running on an ESP32, both AP and STA network are enabled, AP will listen for WIFI client request, I use an old smartphone as client here. STA will connect to my home network through my Wifi router.
The script starts two TCP servers listening on port 23, one bound to the AP IP address and the other bound to the STA IP address.
Using the smartphone, I connect to the AP and launch a telnet client application to connect to the AP's IP address. Then on my Linux PC, I start a telnet session to the IP address of the STA. The idea is to se…