Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reconnecting with mpfshell to webrepl seldomly works in first try #32

Open
ulno opened this issue Apr 27, 2017 · 3 comments
Open

Reconnecting with mpfshell to webrepl seldomly works in first try #32

ulno opened this issue Apr 27, 2017 · 3 comments

Comments

@ulno
Copy link

ulno commented Apr 27, 2017

Connecting to webrepl via the ws option of mpfshell seems a little less reliable than using webrepl from https://github.com/micropython/webrepl.

Connecting the first time to freshly booted esp8266 usually seems to work (even if I have the feeling that it also sometimes fails when the wireless connection is weak - don't have proof for that yet). However, re-opening the websocket or even closing and re-connecting usually does not work the first time. A second re-connect often succeeds.

The webrepl web frontend seems to work nearly always (only sometimes fails when I used mpfshell in between).

Any idea why this is? What is done differently? Can this be fixed or circumvented?

A transcript of my testsession looks like this:

ulno#ulnoiot:$ mpfshell --loglevel DEBUG --logfile /tmp/mpfshell.log

** Micropython File Shell v0.8.0, [email protected] ** 
-- Running on Python 3.5 using PySerial 3.3 --

mpfs [/]> open ws:192.168.12.57,ulnoiot
Connected to esp8266
mpfs [/]> close
mpfs [/]> open ws:192.168.12.57,ulnoiot

Failed to open: ws:192.168.12.57,ulnoiot

mpfs [/]> open ws:192.168.12.57,ulnoiot
Connected to esp8266
mpfs [/]> open ws:192.168.12.57,ulnoiot

Failed to open: ws:192.168.12.57,ulnoiot

mpfs [/]> open ws:192.168.12.57,ulnoiot
Connected to esp8266
mpfs [/]> exit

The corresponding debug.log

tail -f /tmp/mpfshell.log 
2017-04-27 13:48:08,883	INFO	Micropython File Shell v0.8.0 started
2017-04-27 13:48:08,883	INFO	Running on Python 3.5 using PySerial 3.3
2017-04-27 13:48:27,619	INFO	websocket connected to ws://192.168.12.57:8266
2017-04-27 13:48:34,338	INFO	websocket closed
2017-04-27 13:48:35,957	ERROR	websocket error: Connection is already closed.
2017-04-27 13:48:35,962	INFO	websocket closed
2017-04-27 13:48:40,807	ERROR	
2017-04-27 13:48:57,758	INFO	websocket connected to ws://192.168.12.57:8266
2017-04-27 13:49:04,248	INFO	websocket closed
2017-04-27 13:49:04,275	ERROR	websocket error: Connection is already closed.
2017-04-27 13:49:04,281	INFO	websocket closed
2017-04-27 13:49:09,249	ERROR	
2017-04-27 13:49:23,899	INFO	websocket connected to ws://192.168.12.57:8266
2017-04-27 13:49:28,621	INFO	websocket closed
@ulno
Copy link
Author

ulno commented Apr 28, 2017

So, I assume, the module, I need to look at is mpfshell/mp/conwebsock.py.
Would it be hard to at least enable some kind of auto-reconnect/retry?
Maybe off by default but some kind of wsretry-flag you could give on the command line.
Would it make sense to just play with the timeout? I still just don't understand why mpfshell fails so often and webrepl doesn't? Maybe the websocket handling in python is different than in javascript?
I don't see any special code handling errors in the java script part.

Micropython (https://github.com/micropython/webrepl) provides the python command-line client (webrepl-cli.py) which even does a super simple manual websocket handling (in websocket-helper.py). Maybe using that would increase stability?

Thoughts?

ulno

@ulno
Copy link
Author

ulno commented May 16, 2017

I took a closer look and it seems that switching to raw repl mode messes up the micropython repl. A webrepl reset at connection close seems to fix it.

Here is my current testing fork, there is still a bit too much debug prints in there, but if you feel like testing, check it out:
https://github.com/ulno/mpfshell

@skorokithakis
Copy link
Collaborator

Have you gotten anywhere with this? Websocket connections are currently very flaky and I'd like to fix that.

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

No branches or pull requests

2 participants