Skip to content

gomasy/ruby-btwattch2

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ruby-btwattch2

Ruby toolkit for the RS-BTWATTCH2 Bluetooth power meter

ラトックシステム製 Bluetooth ワットチェッカー RS-BTWATTCH2 を Linux から操作するためのツールです。電圧・電流・電力の計測のほか、電源スイッチの操作や本体 RTC の時刻合わせができます。

動作環境

  • Linux (BlueZ)
  • Ruby 3.x
  • Bundler

インストール

$ bundle install

使い方

Usage: 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-now

Mackerel 連携

Mackerel のカスタムメトリック投稿に準拠したフォーマットで出力することも可能です。

# 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 は定期的に同期してください。(前述の「時刻同期」を参照)

ライセンス

MIT License

About

Ruby toolkit for the RS-BTWATTCH2 Bluetooth power meter

Topics

Resources

License

Stars

4 stars

Watchers

1 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages