webrepl
                                
                                 webrepl copied to clipboard
                                
                                    webrepl copied to clipboard
                            
                            
                            
                        Added support for executing remote commands through the command line.
- Added text flag to ws.write for sending text (terminal) messages.
- Rewrite of help.
- Rewrite of parsing.
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?
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.
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.
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?
Is there another terminal client with this feature? I’d love to see a version of this merged.
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:
- Rewrite of the help
- Introduction of the WebreplCLIclass
- Addition of return value for the command()method.
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.