Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork8.2k
mpremote: Add automatic reconnect feature.#17322
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:master
Are you sure you want to change the base?
Uh oh!
There was an error while loading.Please reload this page.
Conversation
- Handle SerialException on Windows when device disconnects- Print clean 'device disconnected' message instead of stack trace- Fix terminal formatting issues on Linux after disconnect- Return disconnected state after console cleanup to avoid terminal issuesThis ensures proper disconnect messages on both platforms withoutshowing confusing error traces to users.Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
codecovbot commentedMay 19, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@## master #17322 +/- ##==========================================- Coverage 98.54% 98.54% -0.01%========================================== Files 169 169 Lines 21898 21897 -1 ==========================================- Hits 21580 21579 -1 Misses 318 318 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Code size report:
|
Josverl commentedMay 19, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Thanks for the effort.
I have never liked that I find myself needing to type 'resume' to 95% of the commands.
But for this very welcome reconnect behavior, I would propose this to be the default, and to be opted out via That will make the "how do we educate this" so much simpler, Physical disconnection of a battery powered board with a running script.
|
This adds a `reconnect` command that enables automatic reconnectionwhen a device disconnects. The reconnect feature:- For direct port connections: reconnects to the exact same port- For `id:` connections: recoonect to same device on any port- Shows clear status messages during reconnection- Preserves resume state through reconnections- Handles Windows timing issues with retry logicUsage: mpremote connect auto reconnect repl mpremote connect id:1234567890 reconnect replThe reconnect command behaves differently based on connection type:- For `auto` and direct ports: only reconnects to the exact same port- For `id:` connections: finds the device on any available portThis prevents accidental connections to different devices when using automode, while allowing id-based connections to find the device wherever itreappears.Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
Thanks@Josverl for bringing up the defaults! Yes I too have thought it would be better to have I'm certainly interested in this new reconnect feature being on by default, I expect to use it asmy default by adding it to the local config file etc at the very least. I'd certainly be happy to make that change if we get such a concensus from the maintainers! |
Josverl commentedMay 19, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
AFAIK mpremote finding its config file is still broken on Windows -#9573 would be needed for that |
Summary
This PR adds automatic reconnection capability to the mpremote tool. When a MicroPython device disconnects, mpremote can now automatically reconnect to the same device, eliminating the need to manually
restart the tool during development.
The new
reconnect
command enables automatic reconnection to the exact same port, even when usingauto
mode. This is particularly important in multi-device environments where you want to ensure reconnection to the same physical device.Key features:
reconnect
command that works likeresume
(standalone command, not a flag)connect auto
modeconnect id:abc123
mode.Usage:
This PR builds on top of#17321 which improves disconnect message handling.
Testing
Testing was performed on:
Tested scenarios:
All tests confirmed that the tool reliably reconnects to the same physical device.
Trade-offs and Alternatives
The implementation adds minimal code complexity and has no impact on users who don't use the reconnect feature. The reconnect command is opt-in and doesn't affect existing behavior.
Design decisions:
The only trade-off is a small increase in code size from the reconnect logic, which is justified by the significant improvement in developer workflow.