usbrelay: Remote powercycling of embedded hardware during development
I recently switched to a remote embedded development workflow. I write code on a laptop and use VS Code Remote SSH to connect to a development PC, while the target board stays attached there via UART, Ethernet, or an ST-Link debugger. This works well, but when the target hangs I still need a way to power-cycle it from the laptop.
An Ethernet smart socket felt like overkill, so I looked for a smaller USB-based solution. I found inexpensive 2-channel USB relay PCBs on eBay and similar marketplaces. I bought two boards for about €10 total, which makes them roughly €5 each.
These relay boards can be used to remove power from the embedded system when needed.
Hardware
The boards use an AVR ATtiny45 MCU and expose a USB HID interface. That means no special driver is needed.

Software
The Linux CLI tool usbrelay by Darryl Bond makes the relay easy to control from the command line.
On Debian/Ubuntu, install it with:
sudo apt-get install usbrelayRunning usbrelay without arguments shows the current state:
sudo usbrelay
relay_1=0
relay_2=0Activate a relay like this:
sudo usbrelay relay_1=1The command prints the current state of all relays:
relay_1=1
relay_2=0When a relay is active, its red LED lights up.
For more detail, usbrelay -d prints board information and USB device data:
sudo usbrelay -d
libusbrelay: 1.0-2.2build4
usbrelay: 1.0-2.2build4
enumerate_relay_boards()Found 1 devices
Device Found
type: 16c0 05df
path: /dev/hidraw0
serial_number: relay
Manufacturer: www.dcttech.com
Product: USBRelay2
Release: 100
Interface: 0
Number of Relays = 2
Module_type = 1
relay_1=1
relay_2=1Next steps
The next step for me is to integrate usbrelay into pytest so power-cycling can be automated during embedded test runs. There is also a Python extension for usbrelay, so that should be possible.
For now, I’m happy that I can continue remote embedded development without having to run back to the lab bench every time the target needs a reboot.