Skip to content

Added support for executing remote commands through the command line. #28

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

Closed
wants to merge 2 commits into from

Conversation

dov
Copy link

@dov dov commented Apr 4, 2017

  • Added text flag to ws.write for sending text (terminal) messages.
  • Rewrite of help.
  • Rewrite of parsing.

@@ -36,13 +36,14 @@ def __init__(self, s):
self.s = s
self.buf = b""

def write(self, data):
def write(self, data, text=False):
OpCode = 1 if text else 2
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Codestyle: you violate both PEP8 and convention of this file (which of course uses standard_python_style).

webrepl_cli.py Outdated
l = len(data)
if l < 126:
# TODO: hardcoded "binary" type
hdr = struct.pack(">BB", 0x82, l)
hdr = struct.pack(">BB", 0x80+OpCode, l)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PEP8 violation: spacing around operators.

print(" %s script.py 192.168.4.1:/another_name.py" % exename)
print(" %s script.py 192.168.4.1:/app/" % exename)
print(" %s 192.168.4.1:/app/script.py ." % exename)
exename = os.path.basename(sys.argv[0])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rewrite of help.

That maybe even nice (maybe not), but definitely can't be part of a commit with the description "Added support for executing remote commands through the command line.". One commit - one logical change. Each change should be grounded (i.e., there should be arguments why change is needed).

@pfalcon
Copy link
Contributor

pfalcon commented Apr 5, 2017

Thanks for the submission, but the patch has multiple issue. Are you aware that there're other tools which already implement (should implement IIRC) this functionality?

@dov
Copy link
Author

dov commented Apr 6, 2017

Thanks for the comments, and for webrepl! I admit that the changes in this pull request was more of a sloppy hack for learning how to communicate with the esp8266, but I thought that there is no harm in trying to contribute it back. Let me know if you think whether you think my patch in within the scope of how you envision webrepl_cli and I'll make the effort to clean it up. If not, that's fine with me as well.

@pfalcon
Copy link
Contributor

pfalcon commented Apr 7, 2017

We, MicroPython maintainers, are trying to concentrate on the core interpreter and libraries. So, as long as there're community utility/tooling projects, our preference is to save maintenance efforts on our side, and vice-versa, encourage their further development and maintenance on community side. So, I'd really recommend to see if there's a tool which already suits your needs among those listed in https://forum.micropython.org/viewtopic.php?f=16&t=1908 (and on that forum in general), and if you see opportunity to improve them/it, to contribute to them instead.

@dov
Copy link
Author

dov commented Apr 8, 2017

I understand and I accept this policy, but I have a few comments:

  • If the purpose of webrepl_cli.py is to copy, then its name is misleading, and it should more aptly be called e.g. webrepl_copy.py .
  • Providing the password in the command line is in my opinion an appropriate feature within the limited scope that you defined.
  • Since you protect the copy functionality from the communications functionality through if __name__=='__main__', it invites for using the library as an import for other (non-core) python code. In such a case the ascii option that I added is missing in order to send webrepl commands.

If I were to address the latter two issues in code style complient separate pull requests, would that be more acceptable?

@roger-
Copy link

roger- commented Oct 3, 2017

Is there another terminal client with this feature? I’d love to see a version of this merged.

* Added text flag to ws.write for sending text (terminal) messages.
* Rewrite of help.
* Rewrite of parsing.
@dov
Copy link
Author

dov commented Oct 1, 2022

I just updated my master branch, and added the following functionality:

  • Placed all the connection functionality into a class for easy reuse.
  • Made the command option return the micropython webrepl output. This means that it can be used as a simple RPC protocol. E.g. the following command line returns the input value of D8:
$ ./webrepl_cli.py --passwd secret --host 192.168.1.220 --cmd 'machine.Pin(15,machine.Pin.IN).value()'
0

The python interface is just as simple. Here is the same command from python:

from webrepl_cli import WebreplCLI

wc = WebreplCLI(host = '192.168.1.220',
                password = 'secret')

print(wc.command('machine.Pin(15,machine.Pin.IN).value()'))

A nice usage for the RPC is to create a few commands in main.py on the micropython side. E.g.:

def d8():
      return machine.Pin(15,machine.Pin.IN).value())

And then you can just do RPC to this method:

$ ./webrepl_cli.py --passwd secret --host 192.168.1.220 --cmd 'd8()'
0

This is obviously more useful for more complex functions.

Since my previous pull request was ignored without explanation during the last four years, I doubt that there will be any interest in merging this either. If there were, I'd separate this change into at least three separate commits/pull requests:

  1. Rewrite of the help
  2. Introduction of the WebreplCLI class
  3. Addition of return value for the command() method.

@dov
Copy link
Author

dov commented Oct 10, 2022

I closed this pull request, in order to free up my master branch for additional work. If there is any interest, I'll be happy to open a new pull request based on a different branch.

@dov dov closed this Oct 10, 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.

3 participants