Skip to content

net/webrepl: Support LAN interfaces and fix AttributeError on ports without WLAN#1116

Open
AsinoEsel wants to merge 1 commit into
micropython:masterfrom
AsinoEsel:fix/webrepl-wlan-attributeerror
Open

net/webrepl: Support LAN interfaces and fix AttributeError on ports without WLAN#1116
AsinoEsel wants to merge 1 commit into
micropython:masterfrom
AsinoEsel:fix/webrepl-wlan-attributeerror

Conversation

@AsinoEsel
Copy link
Copy Markdown

WebREPL currently does not support LAN interfaces, and raises an AttributeError on webrepl.start() on boards without network.WLAN, such as the ESP32-P4 port. The exception is raised in setup_conn() in line 105:

    for i in (network.WLAN.IF_AP, network.WLAN.IF_STA):

Steps to reproduce:

  1. Flash the latest firmware for the ESP32-P4 port
  2. Inside the REPL, configure WebREPL using import webrepl_setup
  3. If configured to enable on startup, it will immediately raise:
  File "<stdin>", line 1, in <module>
  File "webrepl.py", line 1, in start
  File "webrepl.py", line 1, in setup_conn
AttributeError: 'module' object has no attribute 'WLAN'

This PR adds

  1. a try-except block for the existing WLAN logic, to catch this AttributeError.
  2. support for LAN interfaces, with a try-except block to catch errors (such as a TypeError in the event that the LAN interface has not yet been initialized).
  3. A fallback for when neither type of interface has been found.

I have tested this on an ESP32-P4-ETH board, and a generic ESP32 board. Works as intended.

This issue was raised before in #920 by @Romaric-RILLET, but that attempted fix failed to cover the network.WLAN AttributeError (as it happens outside the try-except block), making it impossible for ethernet-only boards to use WebREPL.

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 micropython#920 by @Romaric-RILLET.

Signed-off-by: AsinoEsel <lerefff@gmail.com>
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.

1 participant