oscaracena / pygattlib

Other
62 stars 12 forks source link

terminate called after throwing an instance of 'boost::python::error_already_set' #18

Closed yosoufe closed 3 years ago

yosoufe commented 3 years ago

Hi,

I am using the gattlib 0.20150805 with the BLE example for STM32 nucleo board with the X-NUCLEO-1DB05A1 BLE expansion board. The python library crashes on reading some of the characteristics while the gatttool command line works fine.

gatttool sample output:

$ gatttool -b D5:C9:57:C2:25:7B -t random -I
[D5:C9:57:C2:25:7B][LE]> connect 
Attempting to connect to D5:C9:57:C2:25:7B
Connection successful
[D5:C9:57:C2:25:7B][LE]> characteristics 
handle: 0x0002, char properties: 0x20, char value handle: 0x0003, uuid: 00002a05-0000-1000-8000-00805f9b34fb
handle: 0x0006, char properties: 0x4e, char value handle: 0x0007, uuid: 00002a00-0000-1000-8000-00805f9b34fb
handle: 0x0008, char properties: 0x4e, char value handle: 0x0009, uuid: 00002a01-0000-1000-8000-00805f9b34fb
handle: 0x000a, char properties: 0x02, char value handle: 0x000b, uuid: 00002a04-0000-1000-8000-00805f9b34fb
handle: 0x000d, char properties: 0x12, char value handle: 0x000e, uuid: 00140000-0001-11e1-ac36-0002a5d5c51b
handle: 0x0010, char properties: 0x10, char value handle: 0x0011, uuid: 00e00000-0001-11e1-ac36-0002a5d5c51b
handle: 0x001d, char properties: 0x10, char value handle: 0x001e, uuid: 00000100-0001-11e1-ac36-0002a5d5c51b
[D5:C9:57:C2:25:7B][LE]> char-read-hnd 0x000e
Characteristic value/descriptor: 96 2e 44 a6 01 00 36 01 

while this python script (ble.py)

import sys
# from bluetooth.ble import GATTRequester
from gattlib import GATTRequester

class Reader:
    def __init__(self, address):
        self.requester = GATTRequester(address, False)
        self.connect()
        self.request_name()

        characteristics = self.requester.discover_characteristics()
        for ch in characteristics:
            print(ch)

        data = self.requester.read_by_handle(14) # same as 0x000e
        print(data)

    def connect(self):
        print("Connecting...", end=" ")
        sys.stdout.flush()
        self.requester.connect(True, channel_type="random")
        print("OK.")

    def request_name(self):
        data = self.requester.read_by_uuid(
            "00002a00-0000-1000-8000-00805f9b34fb")[0]
        try:
            print("Device name:", data.decode("utf-8"))
        except AttributeError:
            print("Device name:", data)

if __name__ == "__main__":
    reader = Reader("D5:C9:57:C2:25:7B")
    print("Done.")

is generating following output

$ sudo python3 ble.py 
Connecting... OK.
Device name: BlueNRG
{'uuid': '00002a05-0000-1000-8000-00805f9b34fb', 'handle': 2, 'properties': 32, 'value_handle': 3}
{'uuid': '00002a00-0000-1000-8000-00805f9b34fb', 'handle': 6, 'properties': 78, 'value_handle': 7}
{'uuid': '00002a01-0000-1000-8000-00805f9b34fb', 'handle': 8, 'properties': 78, 'value_handle': 9}
{'uuid': '00002a04-0000-1000-8000-00805f9b34fb', 'handle': 10, 'properties': 2, 'value_handle': 11}
{'uuid': '00140000-0001-11e1-ac36-0002a5d5c51b', 'handle': 13, 'properties': 18, 'value_handle': 14}
{'uuid': '00e00000-0001-11e1-ac36-0002a5d5c51b', 'handle': 16, 'properties': 16, 'value_handle': 17}
{'uuid': '00000100-0001-11e1-ac36-0002a5d5c51b', 'handle': 29, 'properties': 16, 'value_handle': 30}
terminate called after throwing an instance of 'boost::python::error_already_set'
Aborted

which is crashing at data = self.requester.read_by_handle(14) line with error message terminate called after throwing an instance of 'boost::python::error_already_set'

yosoufe commented 3 years ago

Sorry to bother. Too old version, Newer versions does not have the issue.

oscaracena commented 3 years ago

Good yo know! 🙂👍