IanHarvey / bluepy

Python interface to Bluetooth LE on Linux
Other
1.6k stars 491 forks source link

Does the test code for btle.py represent the current api? #173

Open timcoote opened 7 years ago

timcoote commented 7 years ago

While trying to get my head around the bluetooth le model, I tried to run the code at the bottom of btle.py, but automating the identification of a mac address (as these keep changing).

However, at line 722:

    for svc in conn.services:

The type of svc is , although I think that it is supposed to be . Thus the line 724:

            for ch in svc.getCharacteristics():

fails with:

AttributeError: UUID instance has no attribute 'getCharacteristics'

If svc is used to get the service with conn.getServiceByUUID, the code seems to work:

        for svcuuid in conn.services:
            svc = conn.getServiceByUUID (svcuuid)

Have I misunderstood how this should work, or is there a bug in this test code?

timcoote commented 7 years ago

I forgot to mention that after the creation of conn = Peripheral (addr, type) - line 720 - I had to add a call to conn.getServices() to get the conn.services property populated.

I'm using bluez-5.43-1.fc25.i686, on a stock fedora 25 build with an external btle dongle. btle devices are simulated with PunchThrough's BLE tool on an iPad

IanHarvey commented 7 years ago

I'm not sure how this can happen with the latest code. In this, the services property returns self._serviceMap.values(), which is set up by discoverServices(), which creates Service objects for each value in the dictionary.

Could you try again with latest code and see if the problem still persists? If so, can you add

        print (repr(conn._serviceMap))

after the for svc in conn.services: line, and tell me what happens?