ESP32远程WebREPL接入:TCP隧道代码阻塞问题排查
ESP32 TCP隧道转发WebREPL阻塞问题
我需要远程访问ESP32控制台,计划让ESP32主动向服务器建立TCP隧道,将WebREPL客户端与服务器的连接通过隧道转发到ESP32本地的WebREPL服务(8266端口)。自己编写的代码尝试用uasyncio实现并行转发,但出现阻塞问题,试过threads也没解决。
连接架构
- 服务器监听两个端口:
- 端口1:供ESP32建立持久TCP隧道,用于转发单片机侧流量
- 端口2:接收WebREPL客户端的外部连接
- ESP32脚本连接服务器建立隧道后,将隧道数据转发至本地8266端口的WebREPL服务
当前问题症状
- 代码阻塞:运行后卡在
WebREPL connection from: ('127.0.0.1', 51639),仅能通过Ctrl-C中断,中断后触发WebREPL相关报错:
Traceback (most recent call last): File "webrepl.py", line 43, in accept_conn File "websocket_helper.py", line 20, in server_handshake KeyboardInterrupt:
- 日志异常:首次连接服务器时日志出现异常片段:
[...] Checkpoint 1: False; None; None Connecting to ('159.223.29.36', 12014)... Connected to ('159.223.29.36', 12014) Checkpoint 2: True; <socket>; None Connecting to ('localhost', 8266)... Connected to ('localhost', 8266) Checkpoint 3: True; <socket>; <socket> Starting tasks... Tasks started... Tunnel daeomon sleeping Checkpoint 4: True; <socket>; <socket> Checkpoint 5: True; None; None Checkpoint 1: False; None; None [...]
具体异常点:
- Checkpoint 5处Socket变量为空,且未执行
await uasyncio.sleep(5) - 日志显示“Starting tasks...”,但未输出预期的任务启动日志:
Started forwarding loop: remote -> localhost:8266 Entered async_recvfrom(sock, count) Started forwarding loop: localhost:8266 -> remote Entered async_recvfrom(sock, count)
寻求解决代码阻塞及日志异常问题的方法。
内容的提问来源于stack exchange,提问作者alessionossa
相关产品推荐
相关产品推荐

