-
Notifications
You must be signed in to change notification settings - Fork 297
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
Add webrepl_client.py remote shell using MicroPython WebREPL protocol #37
Conversation
…ocol. Update README.md with description and sample.
…t for switching REPL modes: $ ./webrepl_client.py 192.168.4.1 Password: WebREPL connected >>> E paste mode; Ctrl-C to cancel, Ctrl-D to finish === D >>> A raw REPL; CTRL-B to exit >B MicroPython v1.9.4-8-ga9a3caad0 on 2018-05-11; ESP module with ESP8266 Type "help()" for more information. >>> exit $
… and 'D' escape sequences. You can end this endless loop: >>> while True: ... print(".") ... ... ... with either pressing CTRL-C or pressing 'C' and ENTER. You can leave Paste mode with either CTRL-D or 'D' and ENTER. Beware of CTRL-D or 'D' and ENTER in normal mode: This will do module soft reset and hang WebREPL session!
Now mode switching perfect (raw mode not invisible): $ ./webrepl_client.py 192.168.4.1 Password: WebREPL connected >>> A raw REPL; CTRL-B to exit >B MicroPython v1.9.4-8-ga9a3caad0 on 2018-05-11; ESP module with ESP8266 Type "help()" for more information. >>> E paste mode; Ctrl-C to cancel, Ctrl-D to finish === D >>> E paste mode; Ctrl-C to cancel, Ctrl-D to finish === >>> E paste mode; Ctrl-C to cancel, Ctrl-D to finish === >>> exit $
Fix output of OK\x04\x04> to correctly OK>
Fixd missing cases of raw_mode OK\x04\x04>
I did a major rewrite of webrepl_client.py, now all modes (raw/normal/paste) work and only minimal difference for raw mode remains wrt screen terminal session. Documentation now fully describes webrepl_client.py features and demontrates with sample session: If pull request gets accepted, then it should be on last commit and not on the commit requested initially. |
Because micropython/micropython Issue 4196 initial prompt on (re)connect is always ">>> ", regardless of real mode at that time. The fix relies on knowing the prompt based on mode, waiting for it to be sent from MicroPython, and then presenting it as part of input(prompt). Only this ways editing of 5 leftmost chars in history commands works. This fix will ensure that initial mode is always normal mode. This is done by injecting CTRL-C CTRL-B after password input, resulting in MicroPython being in normal mode, regardless of real mode on connect.
Passing password via "-p" overcomes getpass.getpass() redirect issues. "-dbg" only needed when webrepl_client.py does not worki as expected. "-r" indicates that input is redirected, allowing for this: $ ./webrepl_client.py -p abcd -r 192.168.4.1 < <(sleep 1 && echo "E" && cat sc.py && echo -e "D\nc(7)\nexit") Password: WebREPL connected >>> >>> MicroPython v1.9.4-481-g3cd2c281d on 2018-09-04; ESP module with ESP8266 Type "help()" for more information. >>> E paste mode; Ctrl-C to cancel, Ctrl-D to finish === def s(x): === return x*x === def c(x): === return x*s(x) === D >>> c(7) 343 >>> exit $
I tried to use your PR, but I'm getting this error (running with py3):
Installing |
for the error "module 'websocket' has no attribute 'enableTrace'" you must install websocket-client: |
Closed in favour of the feature being added to webrepl_cli.py, as done in 1e09d9a |
webrepl_client.py is pep8online.com checked without errors/warnings.
It runs under python v2 as well as v3.
Very convenient for running Micropython remote shell on a mobile device with small display where browser just is too big.
I use webrepl_client.py on 40x30 console (320x240 display) of Raspberry Pi ZeroW to run Micropython on ESP-01s module attached to flying drone, for servo bomb drop mechanism for now.