Upload
kenichiro-matohara
View
1.910
Download
7
Embed Size (px)
DESCRIPTION
"東海道らぐ 秋の大阪LT大会 in KOF - 東海道らぐ | Doorkeeper" http://tokaidolug.doorkeeper.jp/events/16667 での発表予定スライド
Citation preview
技適なBluetooth GNSS/GPSレシーバーをRaspberryPiで作り
たい
KenichiroMATOHARA(matoken)<[email protected]>
東海道らぐ 秋の大阪LT大会 in KOF2014-11-08(Sat)
Kenichiro MATOHARA
● @matoken● http://matoken.org/● 興味
– Linux
– FLOSS
– OpenSteetMap– 電子工作– :
© OpenStreetMapへの協力者
鹿児島らぐ
● 今のところ鹿児島Linux勉強会を月1回開催– 今回第6回で0回目から数えて7回目の開催
● 鹿児島Linux勉強会– Linux読書会– Linux関連の発表– その他…
● これからの予定– 来月オープンソースカンファレンス2014福岡出展 http://www.ospn.jp/osc2014-fukuoka/
– オープンソースアンカンファレンス鹿児島開催– OSMもそろそろやりたい
精度の高いGPSモジュールを利用して位置測定をしたい
● OpenStreetMap Foundation Japanのmiurahrさんの小江戸らぐ9月のオフな集まり発表資料を見る
● "技適な Bluetooth GNSS/GPS レシーバーの作成と活用”
● 面白そう!● BluethoothSPPモジュールは持ってないけれど
RaspberryPiやUSB Bluethoothモジュールはあるのでこれで真似したい
● ついでに単体でログ取りとかもするようにしたい
準天頂測量衛星システムとかが使えたら街中でも安定す
るかも…
用意したもの
● RaspberryPi B+(A/Bでもok)● USB Bluethoothドングル
– 5種類くらい持っていてこれまでに使えなかった物はないが,購入前に型番で検索して利用できるか確認したほうが無難
● OSはRaspberryPi標準のRasbianを利用(DebianWheezyベース)
● TTLが出てるGPSモジュール(GT-723F 秋月電子で\2,800)● Android端末にSPP接続が出来るBluetooth Terminalを導入(デバッグ用)
● Android端末にBluetoothGPS を使えるようにするBluetooth GPSを導入
RasbianへのBluetooth関連ソフトウェアの導入
$ sudo apt-get update
$ sudo apt-get upgrade
$ sudo apt-get install bluetooth bluez
デーモンが起動しているのを確認
$ /etc/init.d/bluetooth status
bluetooth is running.
Bluetooth デバイスの確認
$ hcitool devDevices: hci0 E0:91:53:77:E8:99$ hciconfig -ahci0: Type: BR/EDR Bus: USB BD Address: E0:91:53:77:E8:99 ACL MTU: 310:10 SCO MTU: 64:8 UP RUNNING PSCAN RX bytes:10030 acl:8 sco:0 events:191 errors:0 TX bytes:1702 acl:8 sco:0 commands:111 errors:0 Features: 0xff 0xff 0x8f 0xfe 0x9b 0xbf 0x59 0x87 Packet type: DM1 DM3 DM5 DH1 DH3 DH5 HV1 HV2 HV3 Link policy: RSWITCH HOLD SNIFF PARK Link mode: SLAVE ACCEPT Name: 'raspberrypi-0' Class: 0x420100 Service Classes: Networking, Telephony Device Class: Computer, Uncategorized HCI Version: 3.0 (0x5) Revision: 0x1aa1 LMP Version: 3.0 (0x5) Subversion: 0x1aa1 Manufacturer: Cambridge Silicon Radio (10)
周りのデバイス検索
$ hcitool scan
Scanning ...
78:DD:08:B0:1F:37 x201s-0
98:91:20:21:55:78 Bluetooth Keyboard
● ※周りのデバイスは検索可能にしておく
ペアリングが可能なようにモードを変更してペアリング
● ペアリング可能なようにモード変更
$ sudo hciconfig hci0 piscan● ペアリング(ペアリングのキーはこの場合4835)
$ sudo bluetooth-agent 4835
Confirmation request of 396777 for device /org/bluez/2150/hci0/dev_70_F9_27_71_74_5B
※ペア先のデバイスは検出可能にしておく● 周りから見えないようにモードを戻しておく
$ sudo hciconfig hci0 noscan
プロトコル確認
● SPPが利用できるのを確認する
$ sdptool browse local● SPPが登録されていなかったら以下のようにして登
録する
$ sdptool add --channel=22 SP
SPPで接続して通信を試みる
$ sudo rfcomm listen /dev/rfcomm0 22
Waiting for connection on channel 22
Connection from 70:F9:27:71:74:5B to /dev/rfcomm0
Press CTRL-C for hangup
● これで /dev/rfcomm0 を通してSPP通信が出来る
実際に通信してみる
● 受信したり
$ cat /dev/rfcomm0
test
hello
hello pi● 送信したり
$ echo "hello android" > /dev/rfcomm0
GPSモジュールを利用できるようにする
● RaspberryPiのGPIOのシリアルはシステムコンソールに割り当てられているのでこれを解除
● GPSモジュールとRaspberryPiの接続
● GPSモジュールから送られてきた情報を取得
RaspberryPiのシステムコンソール割り当て解除
● /boot/cmdline.txt を以下のように編集(ここは要らないかも?)
編集前
dwc_otg.lpm_enable=0 console=ttyAMA0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait
編集後
dwc_otg.lpm_enable=0 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait
● /etc/inittab の以下の行をコメントアウト若しくは削除
T0:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100
ついでにグループ追加して再起動して反映
● pi ユーザでGPSモジュールが利用できるようにdialout GROUP に pi USER を追加
●
$ sudo addgroup pi dialout
The user `pi' is already a member of `dialout'.
$ id
uid=1000(pi) gid=1000(pi) groups=1000(pi),20(dialout)
$ sudo reboot
GPSモジュールとRaspberryPiの接続
● GPSモジュールの配線
● RaspberryPiの配線
● 配線
GT-723F P1(GND) <---> Pi P1-06(GND)GT-723F P2(PWR) <---> Pi P1-01(3.3V)GT-723F P5(TTL-In) <---> Pi P14(TX)GT-723F P6(TTL-Out) <---> Pi P1-15(RX)
VCC/GND辺りの接続間違えると大抵即壊れるので注意orz
GPSモジュールから送られてきた情報を取得
● GPIOのRX/TXはRaspberryPi上では/dev/ttyAMA0に割り当てられている
● gpscatコマンド(python-gps pkg)で内容を取得する
$ sudo apt-get install python-gps$ gpscat -s 9600 /dev/ttyAMA0
$GPRMC,120834.000,V,0000.0000,N,00000.0000,E,000.0,000.0,280606,,,N*70
$GPGGA,120834.000,0000.0000,N,00000.0000,E,0,00,0.0,0.0,M,0.0,M,,0000*61
$GPGSA,A,1,,,,,,,,,,,,,0.0,0.0,0.0*30
$GPGSV,2,1,07,02,63,062,,26,59,190,,05,55,342,,10,30,043,*7B
$GPGSV,2,2,07,29,24,314,,15,23,212,,12,07,232,*46
:
GPSモジュールの情報をBluetoothでAndroidに送ってみる
● AndroidとRaspberryPiがペアリング出来ている状態で
$ gpscat /dev/ttyAMA0 > /dev/rfcomm0
● Andorid側はBluetooth Terminalを利用
AndroidでGPS情報として表示
● Bluetooth GPSを利用https://play.google.com/store/apps/details?id=googoo.android.btgps
● 「Enabke Mock GPS Provider」にチェックを付けることで他のAndroidアプリでもGPS情報が利用可能に
内蔵GPSをoffにしてももちろん動く
Androidのアプリを幾つか試す
● OSMAnd+ OK● GoogleMap OK● OSMTracker for Android NG● MyTrack NG(データ変換で行ける?)● Ingress NG
OSMAnd+
● GPS利用OK● ログ取りもOK● GPSステータスの処理はでき
ていない?
NG
いけるかも?
● GPSデータを変化すればいけるかも?
● ヘルスセンサ用かも?
これから
● Bluethooth自動接続
● DiskのRO化(電源断に対処するため)● GPSのデータをローカルに保存するようにする(領域を分けて保存できるようにする)● 持ち運びやすくする● 性能のいいGNSS GPS利用(SBU3333T MTK3333 TTLレベル 中国GPS北斗対
応)● iOS対応
● GPSコマンド利用
● その他– BUN/PAN等のプロトコルも試してみたい(Bluethoothモバイルルータ化)
参考URL
● "技適な Bluetooth GNSS/GPS レシーバーの作成と活用" https://dl.dropboxusercontent.com/u/90779460/Bluetooth_GNSS_receiver_201409.pdf
● "ja/BluetoothUser - Debian Wiki" https://wiki.debian.org/ja/BluetoothUser
● "Gentoo Linux ドキュメント -- Gentoo Linux Bluetoothガイド" https://www.gentoo.org/doc/ja/bluetooth-guide.xml