mpremote REPL and mount issues with socket:// and RFC2217 connections
Port, board and/or hardware
Any platform - affects mpremote tool when connecting via socket:// or RFC2217
MicroPython version
- mpremote 1.27.0
- Tested against MicroPython unix port 1.27.0 via
- socket://localhost:port
- rfc2217://localhost:2217
Reproduction
1 unable to mount host filesystem over socket connections
- mpremote connect socket://localhost:2218 mount .
AttributeError: 'SerialIntercept' object has no attribute 'in_waiting'
2 Incorrect newline handling in interactive repl over socket
-
Connect to MicroPython Unix port:
mpremote connect socket://localhost:2218 repl -
Type commands and observe output appears like:
>>> print("hello") hello >>>
3 repl over socket://
mpremote connect socket://localhost:2218 repl
REPL may fail to respond or hang
4 repl over rfc2217
mpremote connect rfc2217://localhost:2217 repl
Output may be delayed, laggy, or appear in bursts
pyserial's RFC2217 implementation uses a background thread to process telnet data from the socket into an internal buffer. When mpremote's REPL loop usesselect()on the socket, it signals "ready" when data arrives, butinWaiting()returns 0 because the background thread hasn't processed the data yet.
Race condition sequence:
select()returns because socket has datainWaiting()returns 0 (background thread hasn't processed yet)- REPL loop skips reading
- Next iteration:
select()returns, nowinWaiting() > 0 - Finally reads the data
This causes noticeable lag and stuttering in the REPL.
Expected behaviour
mpremote should work correctly with socket-based connections (socket://, RFC2217), providing:
- Functional mount operations
- Proper newline handling in REPL output
- Responsive REPL without lag or race conditions
Observed behaviour
- Mount operations fail with
AttributeError - REPL output has "staircase" effect (misaligned lines)
- REPL may hang or fail to get input from socket connections
- REPL output is laggy/stuttering with RFC2217 connections
Additional Information
aeb1ce6- Addin_waitingproperty to SerialIntercept class2d46d52- Fix REPL newline handling7f0abfd- Improvewaitchar()wrt socket connections1ff555c- Fix REPL race conditions with RFC2217
Code of Conduct
Yes, I agree
mpremote: Add rfc2217, serial over tcp.
This PR adds the capability fror mpremote to connect to (simulated) boards that are accessible via remote serial ports, or serial over TCP based on rfc2217
To connect to a device use the following
mpremote connect rfc2217://localhost:4000
Implementation:
pyserial already has built-in support for rfc2217 so I have implemented it as a minor addition to the serial protocol.
It would be simple to add support for a straight tcp pipe ( using socket://host:port ) if there is use for that as well.
Some rfc2217 servers that can be used on a (remote) machine to connect to:
- ser2net
- WokWi simulator of esp32 and rp2 boards
https://docs.wokwi.com/vscode/project-config#serial-port-forwarding - Pyserial example servers
com2tcp-rfc2217.batfrom hub4com ](https://sourceforge.net/projects/com0com/files/)