ubuntu16でpythonのbluetooth開発環境を構築2
前回やったのはその後エラーで大変だったので、ちょっとやり直し。
環境
ubuntu16.04
python3.5.2
bluepyインストール
bluepy · PyPI
↑まず、ここからダウンロードしておく
2018/10/26現在最新は1.2.0
cd sudo apt-get install libglib2.0-dev tar -xzvf IanHarvey-bluepy-v-1.1.4-0-g117ac3d.tar.gz cd IanHarvey-bluepy-117ac3d/ sudo python3 setup.py build sudo python3 setup.py install
・インストール成功しているか確認
cd IanHarvey-bluepy-v-1.1.4-0-g117ac3d/bluepy python scanner.py Traceback (most recent call last): File "scanner.py", line 18, in <module> scanner.scan(10.0, passive=True) File "/usr/local/lib/python3.5/dist-packages/bluepy-1.1.4-py3.5.egg/bluepy/btle.py", line 679, in scan self.start(passive=passive) File "/usr/local/lib/python3.5/dist-packages/bluepy-1.1.4-py3.5.egg/bluepy/btle.py", line 617, in start self._mgmtCmd("le on") File "/usr/local/lib/python3.5/dist-packages/bluepy-1.1.4-py3.5.egg/bluepy/btle.py", line 276, in _mgmtCmd "Failed to execute mgmt cmd '%s'" % (cmd)) bluepy.btle.BTLEException: Failed to execute mgmt cmd 'le on'
エラーが出る(今になって思うとこの時bluetoothドングル挿してなかったかも...)
また、2行目のfrom __future__ import print_functionは消しておく
・bluetoothの確認
(ドングルさして確認)
sudo /usr/local/bin/blescan -i=0 Scanning for devices... Device (new): **:**:**:**:**:** (random), -62 dBm (not connectable) Complete 16b Services: <****> 16b Service Data: <****0000000000000000000000000000000000000000> Manufacturer: <***********>
確認できた
・権限付与
また、調べてるとbluepy-helperでエラーが出てる人が多かったのでこちらも対処
sudo setcap 'cap_net_raw,cap_net_admin+eip' bluepy-helper
・bluepyが使えるか確認
python scanner.py Scanning for devices... Device (new): d2:18:5c:a9:20:33 (random), -43 dBm Flags: <06> Complete Local Name: 'MyBlePeripheral' Complete 128b Services: <1e948df1483194ba754c3e5000003d71>
ちなみに見つかったのはredbearのblenano2(プログラムはこちら)