From fc0dc095308ef037afdd620bf046490b7ec762d0 Mon Sep 17 00:00:00 2001 From: AsinoEsel Date: Fri, 15 May 2026 13:09:53 +0200 Subject: [PATCH] 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: if no active interface is found. Based on #920 by @Romaric-RILLET. Signed-off-by: AsinoEsel --- micropython/net/webrepl/manifest.py | 2 +- micropython/net/webrepl/webrepl.py | 21 +++++++++++++++++---- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/micropython/net/webrepl/manifest.py b/micropython/net/webrepl/manifest.py index 20527db4f..6ff9b53d1 100644 --- a/micropython/net/webrepl/manifest.py +++ b/micropython/net/webrepl/manifest.py @@ -1,4 +1,4 @@ -metadata(description="WebREPL server.", version="0.1.0") +metadata(description="WebREPL server.", version="0.1.1") module("webrepl.py", opt=3) module("webrepl_setup.py", opt=3) diff --git a/micropython/net/webrepl/webrepl.py b/micropython/net/webrepl/webrepl.py index 00da8155c..eabd8eda7 100644 --- a/micropython/net/webrepl/webrepl.py +++ b/micropython/net/webrepl/webrepl.py @@ -102,10 +102,23 @@ def setup_conn(port, accept_handler): listen_s.listen(1) if accept_handler: listen_s.setsockopt(socket.SOL_SOCKET, 20, accept_handler) - for i in (network.WLAN.IF_AP, network.WLAN.IF_STA): - iface = network.WLAN(i) - if iface.active(): - print("WebREPL server started on http://%s:%d/" % (iface.ifconfig()[0], port)) + for i in (0, 1): + try: + iface = network.LAN(i) + if iface.active(): + print("WebREPL server started on http://%s:%d/" % (iface.ifconfig()[0], port)) + return listen_s + except (AttributeError, TypeError, ValueError): + pass + try: + for i in (network.WLAN.IF_AP, network.WLAN.IF_STA): + iface = network.WLAN(i) + if iface.active(): + print("WebREPL server started on http://%s:%d/" % (iface.ifconfig()[0], port)) + return listen_s + except AttributeError: + pass + print("WebREPL server started on http://0.0.0.0:%d/" % port) return listen_s