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

Add webrepl_client.py remote shell using MicroPython WebREPL protocol #37

Closed
wants to merge 31 commits into from

Conversation

Hermann-SW
Copy link

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.

@Hermann-SW Hermann-SW mentioned this pull request Sep 19, 2018
Hermann-SW and others added 18 commits September 19, 2018 19:17
…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>
@Hermann-SW
Copy link
Author

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:
https://github.com/Hermann-SW/webrepl#webrepl-shell

If pull request gets accepted, then it should be on last commit and not on the commit requested initially.

HermannSW added 8 commits September 30, 2018 10:44
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
$
@Kriechi
Copy link

Kriechi commented Dec 29, 2018

I tried to use your PR, but I'm getting this error (running with py3):

Traceback (most recent call last):
  File "./webrepl_client.py", line 207, in <module>
    websocket.enableTrace(False)
AttributeError: module 'websocket' has no attribute 'enableTrace'

I had to use pip3 install websocket first, which gave me gevent-1.3.7 greenlet-0.4.15 websocket-0.2.1. Anything wrong with the dependencies?

Installing websocket-client seems to make it work. Thanks! 👍

@PiR43
Copy link

PiR43 commented Jan 24, 2020

for the error "module 'websocket' has no attribute 'enableTrace'" you must install websocket-client:
pip install websocket-client
@Hermann-SW I found this pull request very usefull, thanks.

@dpgeorge
Copy link
Member

dpgeorge commented Nov 8, 2022

Closed in favour of the feature being added to webrepl_cli.py, as done in 1e09d9a

@dpgeorge dpgeorge closed this Nov 8, 2022
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

Successfully merging this pull request may close these issues.

4 participants