Page 1 of 1
PC python script to run mpremote commands
Posted: Mon Jun 06, 2022 9:01 pm
by PM-TPI
So....
Code: Select all
from mpremote import main
main.main()
returns...
Connected to MicroPython at COM12
Use Ctrl-] to exit this shell
But how do I run say... the 'mpremoyte ls' command ?
main() takes 0 positional arguments... so how do I pass 'ls' ?
I don't want to use bash scripts.
Re: PC python script to run mpremote commands
Posted: Tue Jun 07, 2022 8:14 am
by jahr
Hello,
I'm using it this way
Code: Select all
def _call_mpremote(self, args):
args.insert(0, 'mpremote')
proc = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
try:
out, err = proc.communicate(timeout=None if self._timeout in (None, 0) else self._timeout)
# etc.
where args are arguments of mpremote.
Re: PC python script to run mpremote commands
Posted: Tue Jun 07, 2022 9:53 am
by PM-TPI
jahr
Can't we make calls to mpremote directly
without needing to go back out to OS
Re: PC python script to run mpremote commands
Posted: Tue Jun 07, 2022 12:33 pm
by jahr
PM-TPI wrote: ↑Tue Jun 07, 2022 9:53 am
jahr
Can't we make calls to mpremote directly
without needing to go back out to OS
Maybe. I've tried and did not succeeded. IMHO mpremote is not intended to be called as a module and pyboard.py should be used instead. For my use case, the method described was sufficient.
Re: PC python script to run mpremote commands
Posted: Tue Jun 07, 2022 1:02 pm
by PM-TPI
jahr wrote: ↑Tue Jun 07, 2022 12:33 pm
IMHO mpremote is not intended to be called as a module
https://www.youtube.com/watch?v=EVJA01W9ArI
219 views Oct 26, 2021 Damien George instructs us on how to use mpremote
look at 1min 28 sec
Damien didn't go into any detail in using it as a module.
Thank you jahr... subprocess, learn something new everyday.
Re: PC python script to run mpremote commands
Posted: Wed Jun 08, 2022 6:57 pm
by dhylands
You could also just populate sys.argv and then call main.main()
Re: PC python script to run mpremote commands
Posted: Mon Jun 20, 2022 6:20 am
by jimmo
PM-TPI wrote: ↑Mon Jun 06, 2022 9:01 pm
But how do I run say... the 'mpremoyte ls' command ?
mpremote is built on pyboard.py, and this is designed to be used as a module from your own scripts.
See
https://docs.micropython.org/en/latest/ ... rd-library
You can use pyb.fs_ls(), however this will print out to stdout which is probably not what you want. It would be good to extend these libraries to support this use case.