fg1 / BLEHeartRateLogger

Bluetooth Low-Energy Heart Rate Monitor data logging in Python
Other
127 stars 48 forks source link

gatttool works, BLEHeartRateLogger doesn't #9

Closed ghost closed 3 years ago

ghost commented 6 years ago

I'm playing with a Polar OH1 with a RPi3B+, Rasbian Jessie Lite and CRS8510 A10:

# hcitool lescan
LE Scan ...
A0:9E:1A:17:C8:F4 (unknown)
A0:9E:1A:17:C8:F4 Polar OH1 17C8F42D
^C

# gatttool -b A0:9E:1A:17:C8:F4 -I
[A0:9E:1A:17:C8:F4][LE]> connect 
Attempting to connect to A0:9E:1A:17:C8:F4
Connection successful
[A0:9E:1A:17:C8:F4][LE]> characteristics 
handle: 0x0002, char properties: 0x02, char value handle: 0x0003, uuid: 00002a00-0000-1000-8000-00805f9b34fb
handle: 0x0004, char properties: 0x02, char value handle: 0x0005, uuid: 00002a01-0000-1000-8000-00805f9b34fb
handle: 0x0006, char properties: 0x02, char value handle: 0x0007, uuid: 00002a04-0000-1000-8000-00805f9b34fb
handle: 0x0008, char properties: 0x02, char value handle: 0x0009, uuid: 00002aa6-0000-1000-8000-00805f9b34fb
handle: 0x000c, char properties: 0x02, char value handle: 0x000d, uuid: 00002a29-0000-1000-8000-00805f9b34fb
handle: 0x000e, char properties: 0x02, char value handle: 0x000f, uuid: 00002a24-0000-1000-8000-00805f9b34fb
handle: 0x0010, char properties: 0x02, char value handle: 0x0011, uuid: 00002a25-0000-1000-8000-00805f9b34fb
handle: 0x0012, char properties: 0x02, char value handle: 0x0013, uuid: 00002a27-0000-1000-8000-00805f9b34fb
handle: 0x0014, char properties: 0x02, char value handle: 0x0015, uuid: 00002a26-0000-1000-8000-00805f9b34fb
handle: 0x0016, char properties: 0x02, char value handle: 0x0017, uuid: 00002a28-0000-1000-8000-00805f9b34fb
handle: 0x0018, char properties: 0x02, char value handle: 0x0019, uuid: 00002a23-0000-1000-8000-00805f9b34fb
handle: 0x001b, char properties: 0x1c, char value handle: 0x001c, uuid: fb005c51-02e7-f387-1cad-8acd2d8df0c8
handle: 0x001e, char properties: 0x10, char value handle: 0x001f, uuid: fb005c52-02e7-f387-1cad-8acd2d8df0c8
handle: 0x0021, char properties: 0x0c, char value handle: 0x0022, uuid: fb005c53-02e7-f387-1cad-8acd2d8df0c8
handle: 0x0024, char properties: 0x10, char value handle: 0x0025, uuid: 00002a37-0000-1000-8000-00805f9b34fb
handle: 0x0028, char properties: 0x12, char value handle: 0x0029, uuid: 00002a19-0000-1000-8000-00805f9b34fb
handle: 0x002c, char properties: 0x02, char value handle: 0x002d, uuid: fb005c21-02e7-f387-1cad-8acd2d8df0c8
handle: 0x002e, char properties: 0x28, char value handle: 0x002f, uuid: fb005c22-02e7-f387-1cad-8acd2d8df0c8
handle: 0x0031, char properties: 0x10, char value handle: 0x0032, uuid: fb005c26-02e7-f387-1cad-8acd2d8df0c8
handle: 0x0035, char properties: 0x02, char value handle: 0x0036, uuid: 6217ff4c-c8ec-b1fb-1380-3ad986708e2d
handle: 0x0037, char properties: 0x28, char value handle: 0x0038, uuid: 6217ff4d-91bb-91d0-7e2a-7cd3bda8a1f3
[A0:9E:1A:17:C8:F4][LE]> exit

but when I run the application I get:

# ./BLEHeartRateLogger.py -v
2018-06-06 20:44:09,692  Trying to find a BLE device
2018-06-06 20:44:10,857  Establishing connection to A0:9E:1A:17:C8:F4
2018-06-06 20:44:40,963  Connection timeout. Retrying.
2018-06-06 20:44:40,964  Establishing connection to A0:9E:1A:17:C8:F4
^C

This is due to the line 208: it expect a "CON" value while it's still "LE". This works:

i = gt.expect(["Connection successful.", r"\[LE\]"], timeout=30)

The second issue is when it tries to read the characteristics. It seems it sends the command two times and that leads to a fail:

# ./BLEHeartRateLogger.py -d -b
2018-06-06 21:19:57,831  Trying to find a BLE device
2018-06-06 21:19:59,035  Establishing connection to A0:9E:1A:17:C8:F4
[A0:9E:1A:17:C8:F4][LE]> connect
connect
Attempting to connect to A0:9E:1A:17:C8:F4
[A0:9E:1A:17:C8:F4][LE]> 2018-06-06 21:19:59,110  Connected to A0:9E:1A:17:C8:F4
char-read-uuid 00002a19-0000-1000-8000-00805f9b34fb
char-read-uuid 00002a19-0000-1000-8000-00805f9b34fb
Command Failed: Disconnected

and

# ./BLEHeartRateLogger.py -d 
2018-06-06 21:18:09,736  Trying to find a BLE device
2018-06-06 21:18:10,970  Establishing connection to A0:9E:1A:17:C8:F4
[A0:9E:1A:17:C8:F4][LE]> connect
connect
Attempting to connect to A0:9E:1A:17:C8:F4
[A0:9E:1A:17:C8:F4][LE]> 2018-06-06 21:18:11,045  Connected to A0:9E:1A:17:C8:F4
char-desc
char-desc
Command Failed: Disconnected

but using gatttool manually:

# gatttool -b A0:9E:1A:17:C8:F4 -I
[A0:9E:1A:17:C8:F4][LE]> connect
Attempting to connect to A0:9E:1A:17:C8:F4
Connection successful
[A0:9E:1A:17:C8:F4][LE]> char-read-uuid 00002a19-0000-1000-8000-00805f9b34fb
handle: 0x0029   value: 0a 

Anyway, I wasn't able to fix this issue.

bellante commented 4 years ago

I managed to get the Polar OH1 band working. Just connect with addr-type "public" (the default for gatttool) and not "random" Modify line number 200 by removing "-t random"

Hope this can help someone