Sunday, January 8, 2017

pwrusbctl: A command-line tool for controlling USB-connected power strips

Over the past few days I wrote a command-line tool for controlling and monitoring PowerUSB-branded power strips. These are clever devices that connect to a computer via USB and allow power monitoring and controlling the state of the outlets. I decided to call it pwrusbctl and you can view the code on GitHub.

The company that sells them offer a binary blob driver, but I wanted something that I could extend and modify. I also want it to work with my RaspberryPi.

PowerUSB Basic connected to a RaspberryPi
I used HIDAPI as an abstraction over HID which makes the codebase portable. It has been tested to work on Linux and Mac OS. You can find more documentation in the README on GitHub. Here is an example of the output:
[andrew@andrew-rpi-1 pwrusbctl]$ ./pwrusbctl --reset_charge_accumulator --device_info --log_indefinitely --power --energy --interval 2000000
Found PowerUSB device type: Basic
Power: 32.200001W
Energy: 0.000000kWh
Power: 32.200001W
Energy: 0.000537kWh
Power: 27.599998W
Energy: 0.000537kWh
Power: 27.599998W
Energy: 0.000537kWh
Power: 50.599998W
Energy: 0.000537kWh
Power: 172.500000W
Energy: 0.000537kWh
Power: 342.700012W
Energy: 0.000537kWh
Power: 519.799988W
Energy: 0.000537kWh
Power: 545.099976W
Energy: 0.000537kWh