orionrobots / piwars_2024_disasterzone

Code for Piwars 2024 robot
MIT License
2 stars 0 forks source link

PyInfra Yukon Code deployment #31

Closed dannystaple closed 8 months ago

dannystaple commented 8 months ago

Make a simple test, pre-empting the Yukon service to deploy code to it. This route will be desktop-via pyinfra->Raspberry PI-via mpremote->Yukon.

Pyinfra will drive MPRemote to deploy code to the Yukon.

Definition of Ready

Definition of done

dannystaple commented 8 months ago

Removing #32 - we can do this with the NiMH AA's for now.

dannystaple commented 8 months ago

Note - I couldn't see an mpremote apt package, so pip install will work. User is probably good enough.

dannystaple commented 8 months ago

Mpremote is installed, but the Pi cannot find the Yukon when plugged in via USB.

danny@big-ole-yellow:~ $ mpremote devs
/dev/ttyAMA0 None 0000:0000 None None

I've verified I can reach it with MP remote from the MAC using a USB C->C cable. However, from the Pi 3A it must be a USB A->C cable.

Lsusb to list usb devices:

danny@big-ole-yellow:~ $ lsusb
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

Hypotheses:

dannystaple commented 8 months ago

Grabbed a standard Pico on a USB-micro, and checked that mpremote ls works from my laptop. I've plugged into the Raspberry Pi, and this works first time. I am highly suspecting that none of those USB-A->C cables are good.

dannystaple commented 8 months ago

Made that work with the yukon with a known good USB micro cable and USB micro to C adaptor. Rubbish cables. A new tester is on the way for that.

dannystaple commented 8 months ago

With debug, looks like this:

--> Beginning operation run...
--> Starting operation: Install mpremote 
    [pyinfra.api.operations] Starting operation {'Install mpremote'} on big-ole-yellow.local
    [big-ole-yellow.local] No changes

--> Starting operation: Copy test file 
    [pyinfra.api.operations] Starting operation {'Copy test file'} on big-ole-yellow.local
    [pyinfra.connectors.ssh] Attempting upload of /Users/danielstaple/git_work/orionrobots/piwars_2024_disasterzone/robot/services/pimoroni_yukon/rp2040/test_flash_leds.py to mpremote/main.py
    [pyinfra.connectors.ssh] Running command on big-ole-yellow.local: (pty=None) sh -c '/home/danny/.local/bin/mpremote cp mpremote/main.py :main.py'
    [pyinfra.connectors.ssh] Waiting for exit status...
    [pyinfra.connectors.ssh] Command exit status: 0
    [big-ole-yellow.local] Success

--> Starting operation: Reset the Yukon 
    [pyinfra.api.operations] Starting operation {'Reset the Yukon'} on big-ole-yellow.local
    [pyinfra.connectors.ssh] Running command on big-ole-yellow.local: (pty=None) sh -c '/home/danny/.local/bin/mpremote reset'
    [pyinfra.connectors.ssh] Waiting for exit status...
    [pyinfra.connectors.ssh] Command exit status: 0
    [big-ole-yellow.local] Success

--> Results:
    Groups: robots / inventory
    [big-ole-yellow.local]   Changed: 2   No change: 1   Errors: 0

I was able to do the full trip deploy, make changes, and deploy again. There's an issue if the file has the same size (which results in no change), which can be addressed to complete this.

dannystaple commented 8 months ago

We can get the no change condition to work right now, using sha1 digests of the files:

--> Beginning operation run...
--> Starting operation: Install mpremote 
    [big-ole-yellow.local] No changes

--> Starting operation: Copy test file 
    [big-ole-yellow.local] No changes

--> Results:
    Groups: inventory / robots
    [big-ole-yellow.local]   Changed: 0   No change: 2   Errors: 0