Linux BLE: Difference between revisions
From Variscite Wiki
(Initial version) |
|||
Line 1: | Line 1: | ||
= Scanning for BLE devices = | = Scanning for BLE devices = | ||
Use btmgmt tool to scan for BLE devices and report their MAC address type (random vs public) | Use btmgmt tool to scan for BLE devices and report their MAC address type (random vs public). | ||
<pre> | <pre> | ||
Line 7: | Line 7: | ||
Discovery started | Discovery started | ||
hci0 type 7 discovering on | hci0 type 7 discovering on | ||
hci0 dev_found: 74:B9:AB:CF:13:A9 type LE Random rssi -90 flags 0x0000 | |||
AD flags 0x1a | AD flags 0x1a | ||
name Galaxy S5 | name Galaxy S5 | ||
Line 18: | Line 18: | ||
</pre> | </pre> | ||
In this example a single BLE device was detected, having MAC address 74:B9:AB:CF:13:A9 and random MAC address type | |||
= Connecting to BLE devices = | = Connecting to BLE devices = |
Revision as of 10:54, 9 February 2017
Scanning for BLE devices
Use btmgmt tool to scan for BLE devices and report their MAC address type (random vs public).
root@var-som-mx6:~# btmgmt find Discovery started hci0 type 7 discovering on hci0 dev_found: 74:B9:AB:CF:13:A9 type LE Random rssi -90 flags 0x0000 AD flags 0x1a name Galaxy S5 hci0 dev_found: 00:1A:7D:DA:71:0B type BR/EDR rssi -79 flags 0x0000 name SMTBT hci0 dev_found: 00:1A:7D:DA:71:11 type BR/EDR rssi -96 flags 0x0001 eir_len 5 confirm_name succeeded for 00:1A:7D:DA:71:11 hci0 type 7 discovering off
In this example a single BLE device was detected, having MAC address 74:B9:AB:CF:13:A9 and random MAC address type
Connecting to BLE devices
Use gatttool to connect to BLE devices. Pass "-t random" parameter if scan reported random MAC address.
$ gatttool -b <MAC> [-t random] -I
For example when connecting to "BLE Peripheral Simulator" on Android phone the following is done:
root@var-som-mx6:~# gatttool -t random -b 74:B9:AB:CF:13:A9 -I [74:B9:AB:CF:13:A9][LE]> connect Attempting to connect to 74:B9:AB:CF:13:A9 [74:B9:AB:CF:13:A9][LE]> Connection successful Indication handle = 0x0003 value: 01 00 ff ff [74:B9:AB:CF:13:A9][LE]>