### rpi-power-hat scripts — quick reference

Use the unified wrapper:
`rpi-power-hat <script> [args]`. For setup and quickstart, see `../readme.md`.

### Tools

- mass-storage — boot device as mass‑storage for imaging
- flash-image — flash OS image to the selected port
- get — show power status
- set — control port power
- log-current — log current draw (mA)
- log-power — log power draw (mW)
- ssh — SSH into a device using generated keys
- scp — copy files to a device using generated keys
- get-hostname — show current/previous hostnames
- set-hostname — set a device hostname via SSH

### Usage examples

- `rpi-power-hat mass-storage B1 5`
- `rpi-power-hat flash-image B1`
- `rpi-power-hat get B1`
- `rpi-power-hat set B1 1`
- `rpi-power-hat log-current B1 30 -s`
- `rpi-power-hat log-power T2 30 -s`
- `rpi-power-hat ssh B1`
- `rpi-power-hat ssh B1 ls`
- `rpi-power-hat scp B1 ./file.deb:/tmp/file.deb`
- `rpi-power-hat get-hostname B1`
- `rpi-power-hat set-hostname B1 my-host`

### Ports

Valid ports: `B1`, `B2`, `T1`, `T2` (silkscreened on the HAT)

### Script reference

#### mass-storage
- Boot device as mass‑storage
- Usage: `rpi-power-hat mass-storage <PORT> [MODEL]`
- MODEL: `5` (default), `4`, `0` (Pi Zero 2 W)
- When MODEL is specified, it will be written to the config file for the port

#### flash-image
- Flash OS image using port config
- Usage: `rpi-power-hat flash-image <PORT>`
- Notes:
  - Run `mass-storage` first so the device appears as a target
  - Requires `username`, `model`; optional Wi‑Fi `wlan_ssid`/`wlan_password`
  - Generates unique hostname and SSH keys, updates config file
  - Creates SSH client configuration snippets for easy access

#### get
- Show power status
- Usage: `rpi-power-hat get <PORT|all>`

#### set
- Turn power on/off
- Usage: `rpi-power-hat set <PORT|all> <0|1>`

#### log-current
- Stream or save current draw (mA)
- Usage: `rpi-power-hat log-current <PORT> [DURATION] [-s]`
- Note: `-s` (save to CSV) requires duration to be specified

#### log-power
- Stream or save power draw (mW)
- Usage: `rpi-power-hat log-power <PORT> [DURATION] [-s]`
- Note: `-s` (save to CSV) requires duration to be specified

#### ssh
- Connect to flashed device
- Usage: `rpi-power-hat ssh <PORT> [COMMAND]`
- Optionally run a command on the remote device

#### scp
- Copy a file to a flashed device
- Usage: `rpi-power-hat scp <PORT> <LOCAL_PATH>:<REMOTE_PATH>`
- Uses the same credentials and SSH options as `ssh`

#### get-hostname
- Print current hostname; `-h` shows history
- Usage: `rpi-power-hat get-hostname <PORT> [-h]`

#### set-hostname
- SSH to device, set hostname, update config and client snippet
- Usage: `rpi-power-hat set-hostname <PORT> <NEW_HOSTNAME>`
- Updates both hostname and ssh_host in config file upon success

### Files

- `/etc/rpi-power-hat/ports.conf` — per‑port settings (hostname, username, model, image)
- `/etc/rpi-power-hat/network.conf` — per‑port Wi‑Fi settings (wlan_ssid, wlan_password)
- `/usr/share/rpi-power-hat/scripts/hardware-reader.sh` — hardware helper
- `/var/lib/rpi-power-hat/images/` — OS image store
- `/var/lib/rpi-power-hat/keys/` — generated SSH keys

### See also

- Project README: `../readme.md`



