Ruby toolkit for the RS-BTWATTCH2 Bluetooth power meter
ラトックシステム製 Bluetooth ワットチェッカー RS-BTWATTCH2 を Linux から操作するためのツールです。電圧・電流・電力の計測のほか、電源スイッチの操作や本体 RTC の時刻合わせができます。
- Linux (BlueZ)
- Ruby 3.x
- Bundler
$ bundle installUsage: btwattch2 [options]
-i, --index <index> Specify adapter index, e.g. hci0.
-a, --addr <addr> Specify the destination address.
-n, --interval <second(s)> Specify the seconds to wait between updates.
--on Turn on the power switch.
--off Turn off the power switch.
--set-rtc <time> Specify the time to set to RTC.
--set-rtc-now Set the current time of this system to RTC.
--test-led Blink the LED on the main unit.
--addr に本体の Bluetooth アドレスを指定して実行すると、--interval 秒(デフォルト: 1 秒)ごとに計測値を出力します。
# bundle exec ruby btwattch2.rb --addr CB:DF:6B:12:34:56
V = 104.29123878479004, A = 1.1373979076743126, W = 106.03327941894531
V = 104.19976472854614, A = 1.1281732693314552, W = 105.39636832475662
V = 104.17768478393555, A = 1.1366924941539764, W = 105.92031782865524
...# bundle exec ruby btwattch2.rb --addr CB:DF:6B:12:34:56 --on
# bundle exec ruby btwattch2.rb --addr CB:DF:6B:12:34:56 --off計測値のタイムスタンプは本体の RTC をもとに設定されるため、以下のコマンドを systemd-timer や cron などで定期的に実行して同期してください。
# bundle exec ruby btwattch2.rb --addr CB:DF:6B:12:34:56 --set-rtc-nowMackerel のカスタムメトリック投稿に準拠したフォーマットで出力することも可能です。
# bundle exec ruby mackerel.rb --addr CB:DF:6B:12:34:56 --metric-name wattchecker1
wattchecker1.voltage 104.80763912200928 1609304963
wattchecker1.ampere 1.120739296078682 1609304963
wattchecker1.wattage 104.89565205574036 1609304963注: メトリクスの epoch は本体の RTC をもとに設定されています。RTC は定期的に同期してください。(前述の「時刻同期」を参照)