Raspberry PiにF-PLUGを2個繋いでみた
Raspberry Piにも大分慣れてきたのでF-PLUGを繋いでみることにしました。
まずはBluetooth関連パッケージをインストールします。 $ sudo apt-get install bluetooth bluez-utils bluez-compatドングルを挿して認識していることを確認します。 $ sudo hciconfig -aF-PLUGを1つ近くの電源に接続しペリングします。 $ sudo hcitool scan $ sudo bluetooth-agent 1234 <BTアドレス> ※ F-PLUGのLEDが点灯したらボタンを押しますうまくいったら次のF-PLUGを電源に接続し同様にペアリングします。 /etc/bluetooth/rfcomm.confに設定を追加します。 # # RFCOMM configuration file. # rfcomm0 { # Automatically bind the device at startup bind no; # Bluetooth address of the device device B0:99:28:xx:xx:xx; # RFCOMM channel for the connection channel 1; # Description of the connection comment "F-PLUG No.1"; } rfcomm1 { # Automatically bind the device at startup bind no; # Bluetooth address of the device device B0:99:28:xx:xx:xx; # RFCOMM channel for the connection channel 1; # Description of the connection comment "F-PLUG No.2"; }bluetoothサービスをstop/startします。 $ sudo /etc/init.d/bluetooth stop $ sudo /etc/init.d/bluetooth start準備ができたら2個のF-PLUGをconnectし、つながっていることを確認します。 $ sudo rfcomm -r connect 0 & $ sudo rfcomm -r connect 1 & $ sudo rfcomm -aついでにデバイスもちゃんとできていることを確認しておきます。 pi@raspberrypi ~ $ ls -l /dev/rfc* crw-rw---T 1 root dialout 216, 0 Aug 18 11:11 /dev/rfcomm0 crw-rw---T 1 root dialout 216, 1 Aug 18 11:11 /dev/rfcomm1 pi@raspberrypi ~ $これで準備はOKです。 OBDNマガジンの記事を参考にしてfptest、fpstatusコマンドを作成します。 # git clone https://github.com/goto2048/fplug_for_linux.git # cc fptest.c -o fptest # cc fpstatus.c -o fpstatusコマンドが作成できたら値が取得できることを確認します。 問題はここからです。fptest、fpstatusコマンドは1台目(正確には/dev/rfcomm0につながっている方)のF-PLUGの値しか取得できませんでした。 せっかくソースを提供してくれているので強引に修正してみました。 修正前 fd = open(SERIAL_PORT, O_RDWR ); 修正後 fd = open("/dev/rfcomm1", O_RDWR );SERIAL_PORTと書かれているところを読んで欲しいデバイス(/dev/rfcomm1)に書き換えたのです。 # cc fptest1.c -o fptest1 # cc fpstatus1.c -o fpstatus1これで2台目のF-PLUGの情報を取得するfptest1、fpstatus1コマンドができました。 まだ設定してから1日ほどですが正常に動作しているようです。 もっともF-PLUGを抜いたりすると以降のデータが取れなくなってしまいます。 その際の復旧方法もわかって来ましたのでスクリプト化して自動実行するようにしようかと考えています。 |
「Linuxの小技」書庫の記事一覧
-
2013/11/17(日) 午後 2:41
-
2013/11/9(土) 午後 2:48
-
2013/11/4(月) 午後 6:18
-
2013/9/23(月) 午後 8:03
-
2013/9/21(土) 午前 9:20
-
2013/9/16(月) 午前 10:31
-
2013/8/31(土) 午後 0:44
-
2013/8/25(日) 午後 6:06
-
2013/8/24(土) 午後 8:23
-
2013/8/18(日) 午前 11:41
コメント(0)
※投稿されたコメントはブログ開設者の承認後に公開されます。
トラックバック
トラックバック先の記事
- トラックバック先の記事がありません。