Are there tools like 'ampy' and 'there' that support websocket connections?

Discussion about programs, libraries and tools that work with MicroPython. Mostly these are provided by a third party.
Target audience: All users and developers of MicroPython.
spierepf
Posts: 22
Joined: Mon Jul 08, 2019 3:22 pm

Are there tools like 'ampy' and 'there' that support websocket connections?

Post by spierepf » Sun Aug 14, 2022 5:03 pm

I've tried to use 'ampy' (https://pypi.org/project/adafruit-ampy/) and 'there' (https://pypi.org/project/mpy-repl-tool/) to manage source files on my esp32 running micropython. Neither of these tools appears to support WebREPL.

Are there alternatives that support WebREPL?

cgglzpy
Posts: 47
Joined: Thu Jul 18, 2019 4:20 pm

Re: Are there tools like 'ampy' and 'there' that support websocket connections?

Post by cgglzpy » Sun Aug 14, 2022 9:53 pm

You may want to try upydev, works for serial, WebREPL and BLE.

spierepf
Posts: 22
Joined: Mon Jul 08, 2019 3:22 pm

Re: Are there tools like 'ampy' and 'there' that support websocket connections?

Post by spierepf » Mon Aug 15, 2022 2:44 am

Do you have experience with this tool? I cannot make it work.

For example, I would like to copy the contents of the device into a directory called tmp:

$ upydev dsync -d / tmp
dsync: path .//, ./tmp:
dsync: checking filesystem...
dsync: dirs: none
dsync: files: none
$ ls tmp
$

The device is freshly flashed, so it has a boot,py file on it. But it clearly was not downloaded.

The online docs are sparse on details:

https://upydev.readthedocs.io/en/latest ... operations

cgglzpy
Posts: 47
Joined: Thu Jul 18, 2019 4:20 pm

Re: Are there tools like 'ampy' and 'there' that support websocket connections?

Post by cgglzpy » Mon Aug 15, 2022 5:07 pm

Do you have experience with this tool? I cannot make it work.
Yes I'm the author
The online docs are sparse on details:
I agree on that, probably I should explain better how dsync command works since it may be a bit confusing.
Although every command has its own help info:

Code: Select all

$ upydev dsync -h
usage:  dsync [-h] [-rf] [-d] [-fg] [-b B] [-t] [-f] [-p] [-n]
              [-i [I [I ...]]]
              [dir/pattern [dir/pattern ...]]

recursively sync a folder from/to device's filesystem

* needs shasum.py in device

positional arguments:
  dir/pattern     indicate a dir/pattern to sync

optional arguments:
  -h, --help      show this help message and exit
  -rf             remove recursive force a dir or file deleted in local/device directory
  -d              sync from device to host
  -fg             switch off faster get method
  -b B            read buffer for faster get method
  -t              show tree of directory to sync
  -f              force sync, no hash check
  -p              show diff
  -n              dry-run and save stash
  -i [I [I ...]]  ignore file/dir or pattern
For example, I would like to copy the contents of the device into a directory called tmp:
dsync command considers that your current working directory './' is at the same level of device root '/' directory, so if you want to copy the contents of the device into a directory called tmp do:

Code: Select all

$ mkdir tmp
$ cd tmp
tmp:$ upydev dsync -d
Also be aware you need shasum.py in device so dsync command can work properly

So if your device is freshly flashed do:

Code: Select all

$ upydev update_upyutils shasum.py
This will create a lib folder in the device and put shasum.py there. Now dsync should work as expected.

Note that if you are going to use dsync frequently or do consecutive calls it may be better to enter shell-repl mode first. e.g.

Code: Select all

$ upydev shl
shell-repl @ pybV1.1
SerialREPL connected

MicroPython v1.19.1-217-g5234e1f1e on 2022-07-29; PYBv1.1 with STM32F405RG
Type "help()" for more information.

- CTRL-k to see keybindings or -h to see help
- CTRL-s to toggle shell/repl mode
- CTRL-x or "exit" to exit
pyboard@pybV1.1:~ $
Happy to help if you have any other doubt.

spierepf
Posts: 22
Joined: Mon Jul 08, 2019 3:22 pm

Re: Are there tools like 'ampy' and 'there' that support websocket connections?

Post by spierepf » Mon Aug 15, 2022 5:25 pm

I've uploaded `shasum.py` as you suggested

```
$ upydev update_upyutils shasum.py
```

but when I
```
$ cd tmp
$ upydev dsync -d
upydev: no device configured (upydev_.config file not found)
```

The issue is that `upydev_.config` is in the parent directory...

spierepf
Posts: 22
Joined: Mon Jul 08, 2019 3:22 pm

Re: Are there tools like 'ampy' and 'there' that support websocket connections?

Post by spierepf » Mon Aug 15, 2022 5:55 pm

And even if I copy `upydev_.config` into the `tmp` directory

```
$ upydev dsync -d
dsync: path ./:
dsync: dirs: none

dsync: syncing new files (1):
- ./lib/shasum.py [5.83 kB]

dsync: syncing modified files (1):
- ./boot.py [0.14 kB]

upydevice:./boot.py -> ./boot.py

./boot.py [0.14 kB]
get: Operation failed, reason: invalid syntax (<unknown>, line 1)
Continue get Operation with next file? [y/n]n
Canceling file queue..
```

cgglzpy
Posts: 47
Joined: Thu Jul 18, 2019 4:20 pm

Re: Are there tools like 'ampy' and 'there' that support websocket connections?

Post by cgglzpy » Mon Aug 15, 2022 6:24 pm

mmm I see, does command get, put work for you? I see now I forgot to mention a little detail here that should be in the help/docs info.

You have two options:
To sync from device
  • add -fg flag as $ upydev dsync -d -fg (this switches off the faster get method which needs upysh.py)
or add upysh.py

Code: Select all

$ upydev update_upyutils upysh.py

Now it should work, if it doesn't let me know but I think that's it.

Also for configuration it may be better to save configuration in global path. check $ upydev dm and $ upydev config -h
so you don't need to copy configuration manually.

spierepf
Posts: 22
Joined: Mon Jul 08, 2019 3:22 pm

Re: Are there tools like 'ampy' and 'there' that support websocket connections?

Post by spierepf » Mon Aug 15, 2022 6:33 pm

Is it possible to just specify the device connection details on the command line instead of using a `upydev_.config` file?

cgglzpy
Posts: 47
Joined: Thu Jul 18, 2019 4:20 pm

Re: Are there tools like 'ampy' and 'there' that support websocket connections?

Post by cgglzpy » Mon Aug 15, 2022 8:15 pm

It depends, not all commands work this way, upydev is intended to work with config files.
Preferred method is e.g.:

Code: Select all

$ upydev config -t /dev/tty.usbmodem3370377430372 -g -@ mydevice
Or if working with multiple devices

Code: Select all

$ upydev config -t /dev/tty.usbmodem3370377430372 -g -gg -@ mydevice
Do you have any use case that is preferable to specify connections details on the command line over a config file?
Are you trying to integrate upydev in your own automated workflow or something like that?
Last edited by cgglzpy on Tue Aug 16, 2022 4:12 pm, edited 1 time in total.

spierepf
Posts: 22
Joined: Mon Jul 08, 2019 3:22 pm

Re: Are there tools like 'ampy' and 'there' that support websocket connections?

Post by spierepf » Tue Aug 16, 2022 12:10 am

Do you have any use case that is preferable to specify connections details on the command line over a config file?
Are you trying to integrate upydev in your own automated workflow or something like that?
upydev appears to require its config file to live in the current dir, but dsync also maps the current directory to the root of the upy device.

This makes upydev awkward to use unless you are prepared to send the config file along with the source.

Post Reply