Skip to content

Commit fc0dc09

Browse files
committed
webrepl: Support LAN interfaces and fix WLAN AttributeError.
On ports without network.WLAN (such as the ESP32-P4 port), webrepl crashes on webrepl.start() because network.WLAN is accessed unconditionally in setup_conn(). Add LAN interface support, add try/except around LAN and WLAN access, and add fallback to 0.0.0.0:<port> if no active interface is found. Based on #920 by @Romaric-RILLET. Signed-off-by: AsinoEsel <lerefff@gmail.com>
1 parent 09a33ee commit fc0dc09

2 files changed

Lines changed: 18 additions & 5 deletions

File tree

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
metadata(description="WebREPL server.", version="0.1.0")
1+
metadata(description="WebREPL server.", version="0.1.1")
22

33
module("webrepl.py", opt=3)
44
module("webrepl_setup.py", opt=3)

micropython/net/webrepl/webrepl.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,23 @@ def setup_conn(port, accept_handler):
102102
listen_s.listen(1)
103103
if accept_handler:
104104
listen_s.setsockopt(socket.SOL_SOCKET, 20, accept_handler)
105-
for i in (network.WLAN.IF_AP, network.WLAN.IF_STA):
106-
iface = network.WLAN(i)
107-
if iface.active():
108-
print("WebREPL server started on http://%s:%d/" % (iface.ifconfig()[0], port))
105+
for i in (0, 1):
106+
try:
107+
iface = network.LAN(i)
108+
if iface.active():
109+
print("WebREPL server started on http://%s:%d/" % (iface.ifconfig()[0], port))
110+
return listen_s
111+
except (AttributeError, TypeError, ValueError):
112+
pass
113+
try:
114+
for i in (network.WLAN.IF_AP, network.WLAN.IF_STA):
115+
iface = network.WLAN(i)
116+
if iface.active():
117+
print("WebREPL server started on http://%s:%d/" % (iface.ifconfig()[0], port))
118+
return listen_s
119+
except AttributeError:
120+
pass
121+
print("WebREPL server started on http://0.0.0.0:%d/" % port)
109122
return listen_s
110123

111124

0 commit comments

Comments
 (0)