Twiddle: making flaky bench meters boring
A persistent BLE service turns cheap power meters into stable, named instruments that people, scripts, and agents can share.
Cheap Bluetooth power meters are remarkably useful on a bench. They are also built around a constraint their phone apps conceal: one connection at a time, with a radio that may take several seconds to advertise again after a disconnect.
Twiddle turns that awkward behavior into a dependable local interface. A small service owns one long-lived BLE connection per meter, retries when the link drops, and gives each physical device a stable name. The command line—and any agent using it—talks to the service over a local socket instead of fighting for the radio.
Own the scarce thing once
The key design is broader than Bluetooth. When a resource allows only one fragile connection, do not let every consumer become its own connection manager. Put one process in charge of the scarce thing and expose a calmer contract to the rest of the workshop.
Twiddle reports voltage, current, power, accumulated charge and energy, temperature, and runtime as readable text or JSON. An optional local HTTP endpoint provides read-only values. If the service is not running, a direct one-shot connection remains available for occasional work.
Commands that erase accumulated counters are treated differently from reads. They require confirmation because the reset cannot be undone. The interface carries the consequence instead of assuming every caller has memorized the device protocol.
Test the bytes without the radio
The protocol codec is expressed as pure functions and tested against captured real-device frames. Most development therefore needs no meter and no Bluetooth stack. Hardware remains necessary for final confidence, but it is not allowed to make every test slow or temperamental.
That split—pure protocol, unreliable transport, persistent connection owner, simple client—is a fine little piece of workshop engineering. Twiddle does not make the meter’s BLE module better. It surrounds the weakness with a shape that the rest of the system can rely on.
The project is public at shawnrancatore/twiddle.