トップ 一覧 検索 ヘルプ RSS ログイン

LN-bluetoothの変更点

  • 追加された行はこのように表示されます。
  • 削除された行はこのように表示されます。
! bluez のインストール
 zypper install bluez bluez-devel
 
 https://git.kernel.org/pub/scm/bluetooth/bluez.git
 


! python モデュールのインストール
 zypper install pybluez boot_python3
 pip3 install gattlib 
  ## pip3 install pybluez[ble]  // どっちが正しい??
 ( boot_python-py34 がないとエラーが出るので
   cd /usr/lib64/ 以下で探す
   boot_python-py3 を
   ln -s boot_python-py3 boot_python-py34 )
 pip3 install bluepy

! Wii Remote
 linux is 
 https://github.com/RaphaelWimmer/wiimote.py
 
 https://wiibrew.org/wiki/Wiimote

!open-suse leap で HC-06 を使う

 # hcitool scan
 Scanning ...
 	00:15:83:35:xx:xx	HC-06

 # rfcomm bind rfcomm0 00:15:83:35:xx:xx
 ###### rfcomm release rfcomm0 

 ## もしかすると
 /etc/bluetooth/rfcomm.conf
 
 が必要かも
 内容は
 
 rfcomm0 {
        # Automatically bind the device at startup
        #bind yes;
        bind no;
 
        # Bluetooth address of the device
        # device 01:23:45:67:89:AB;
        device 00:15:83:35:xx:xx;
 
        # RFCOMM channel for the connection
        channel 1;
        # channel 3;
 
        # Description of the connection
        comment "as you like comment";
 }
 となる

 # kermit
 set line /dev/rfcomm0 
 set speed 9600
 connect
 
 #  Kermit の代わりに / screen /dev/rfcomm0 9600
 screen /dev/rfcomm0 9600
  (終了 C-a k (Ctrl+aを押した後に k) )

 1029  sudo hcitool scan
 1030  sudo sdptool records 24:0A:C4:0D:BC:B6
 1031  sudo sdptool search SP 
 1033  sudo rfcomm bind 1 24:0A:C4:0D:BC:B6  
       sudo stty -F /dev/rfcomm1 38400 cs8
 1034  sudo rfcomm release 1


!! APENDIX
! BluetoothCtl の使い方
 
 # bluetoothctl 
 [NEW] Controller 00:15:83:2B:xx:xx linux-crcd [default]
 [NEW] Device 00:15:83:35:XX:XX HC-06
 [bluetooth]# scan on
 Discovery started
 [CHG] Controller 00:15:83:2B:xx:xxx Discovering: yes
 [CHG] Device 00:15:83:35:xx:xx RSSI: -66
 [bluetooth]# pair 00:15:83:35:xx:xx
 Attempting to pair with 00:15:83:35:xx:xx
 Failed to pair: org.bluez.Error.AlreadyExists
 [bluetooth]# trust 00:15:83:35:xx:xx
 Changing 00:15:83:35:xx:xx trust succeeded
 [bluetooth]# connect 00:15:83:35:xx:xx
 Attempting to connect to 00:15:83:35:xx:xx
 [CHG] Device 00:15:83:35:xx:xx Connected: yes
 Failed to connect: org.bluez.Error.NotAvailable
 [CHG] Device 00:15:83:35:xx:xx Connected: no
 [bluetooth]# info 00:15:83:35:xx:xx 
 Device 00:15:83:35:xx:xx
 	Name: HC-06
 	Alias: HC-06
 	Class: 0x001f00
 	Paired: yes
 	Trusted: yes
 	Blocked: no
 	Connected: no
 	LegacyPairing: yes
 	UUID: Serial Port               (00001101-0000-1000-8000-00xxxxxxxxxxxx)
 	RSSI: -66
 [bluetooth]# quit

 > bluetoothctl
 [NEW] Controller 00:09:DD:40:D4:32 linux-ou4m [default]
 [NEW] Device 24:0A:C4:0D:BC:B6 ESP32_BluetoothSerial
 [NEW] Device C9:79:7F:77:8C:31 BatteryMonitor
 Agent registered
 [bluetooth]# scan on 
 Discovery started
 [CHG] Controller 00:09:DD:40:D4:32 Discovering: yes
 [CHG] Device 24:0A:C4:0D:BC:B6 RSSI: -44
 [bluetooth]# scan off 
 [CHG] Device 24:0A:C4:0D:BC:B6 RSSI is nil
 [CHG] Controller 00:09:DD:40:D4:32 Discovering: no
 Discovery stopped
 [bluetooth]# pear 24:0A:C4:0D:BC:B6 
 Invalid command
 [bluetooth]# pair 24:0A:C4:0D:BC:B6 
 Attempting to pair with 24:0A:C4:0D:BC:B6
 [CHG] Device 24:0A:C4:0D:BC:B6 Connected: yes
 Request confirmation
 [ESP31m[agent] Confirm passkey 041359 (yes/no): yes
 [CHG] Device 24:0A:C4:0D:BC:B6 Paired: yes
 Pairing successful
 [CHG] Device 24:0A:C4:0D:BC:B6 Connected: no
 [bluetooth]# trust 24:0A:C4:0D:BC:B6 
 [CHG] Device 24:0A:C4:0D:BC:B6 Trusted: yes
 Changing 24:0A:C4:0D:BC:B6 trust succeeded
 [bluetooth]# exit
 Agent unregistered
 [DEL] Controller 00:09:DD:40:D4:32 linux-ou4m [default]
 > 

 自動起動の設定 ( ExecStart=/usr/lib/bluetooth/bluetoothd  --compat ) に
 > diff ./dbus-org.bluez.service /etc/systemd/system/dbus-org.bluez.service 
 9c9
 < ExecStart=/usr/lib/bluetooth/bluetoothd
 ---
 > ExecStart=/usr/lib/bluetooth/bluetoothd  --compat
 20a21,22
 > 
 > 
 
 ## $ sudo sdptool add --channel=22 SP
 ## Serial Port service registered

 /etc/bluetooth/rfcomm.conf を作成

 ## までやったら(group が daialout になったので )


!hciconfig の使い方
 > hciconfig 
 hci0:   Type: Primary  Bus: USB
        BD Address: 00:15:83:2B:XX:XX  ACL MTU: 310:10  SCO MTU: 64:8
        UP RUNNING 
        RX bytes:546 acl:0 sco:0 events:29 errors:0
        TX bytes:379 acl:0 sco:0 commands:29 errors:0
 
 BT2_Classic ??
 > hciconfig hci0 version 
 hci0:   Type: Primary  Bus: USB
        BD Address: 00:15:83:2B:XX:XX  ACL MTU: 310:10  SCO MTU: 64:8
        HCI Version: 2.0 (0x3)  Revision: 0xc5c
        LMP Version: 2.0 (0x3)  Subversion: 0xc5c
        Manufacturer: Cambridge Silicon Radio (10)
 
 > hciconfig hci0 features 
 hci0:   Type: Primary  Bus: USB
        BD Address: 00:15:83:2B:XX:XX  ACL MTU: 310:10  SCO MTU: 64:8
        Features: 0xff 0xff 0x8f 0xfe 0x9b 0xf9 0x00 0x80
                <3-slot packets> <5-slot packets> <encryption> <slot offset> 
                <timing accuracy> <role switch> <hold mode> <sniff mode> 
                <park state> <RSSI> <channel quality> <SCO link> <HV2 packets> 
                <HV3 packets> <u-law log> <A-law log> <CVSD> <paging scheme> 
                <power control> <transparent SCO> <broadcast encrypt> 
                <EDR ACL 2 Mbps> <EDR ACL 3 Mbps> <enhanced iscan> 
                <interlaced iscan> <interlaced pscan> <inquiry with RSSI> 
                <extended SCO> <EV4 packets> <EV5 packets> <AFH cap. slave> 
                <AFH class. slave> <3-slot EDR ACL> <5-slot EDR ACL> 
                <AFH cap. master> <AFH class. master> <EDR eSCO 2 Mbps> 
                <EDR eSCO 3 Mbps> <3-slot EDR eSCO> <extended features> 
 BLE の場合
 > hciconfig hci0 version 
 hci0:   Type: Primary  Bus: USB
        BD Address: 00:09:DD:40:D4:32  ACL MTU: 310:10  SCO MTU: 64:8
        HCI Version: 4.0 (0x6)  Revision: 0x22bb
        LMP Version: 4.0 (0x6)  Subversion: 0x22bb
        Manufacturer: Cambridge Silicon Radio (10)
 > hciconfig hci0 features 
 hci0:   Type: Primary  Bus: USB
        BD Address: 00:09:DD:40:XX:XX  ACL MTU: 310:10  SCO MTU: 64:8
        Features page 0: 0xff 0xff 0x8f 0xfe 0xdb 0xff 0x5b 0x87
                <3-slot packets> <5-slot packets> <encryption> <slot offset> 
                <timing accuracy> <role switch> <hold mode> <sniff mode> 
                <park state> <RSSI> <channel quality> <SCO link> <HV2 packets> 
                <HV3 packets> <u-law log> <A-law log> <CVSD> <paging scheme> 
                <power control> <transparent SCO> <broadcast encrypt> 
                <EDR ACL 2 Mbps> <EDR ACL 3 Mbps> <enhanced iscan> 
                <interlaced iscan> <interlaced pscan> <inquiry with RSSI> 
                <extended SCO> <EV4 packets> <EV5 packets> <AFH cap. slave> 
                <AFH class. slave> <LE support> <3-slot EDR ACL> 
                <5-slot EDR ACL> <sniff subrating> <pause encryption> 
                <AFH cap. master> <AFH class. master> <EDR eSCO 2 Mbps> 
                <EDR eSCO 3 Mbps> <3-slot EDR eSCO> <extended inquiry> 
                <LE and BR/EDR> <simple pairing> <encapsulated PDU> 
                <non-flush flag> <LSTO> <inquiry TX power> <EPC> 
                <extended features> 
        Features page 1: 0x03 0x00 0x00 0x00 0x00 0x00 0x00 0x00

! Tips
https://qiita.com/propella/items/6daf3c56e26f709b4141