Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple Instances of a single Service #490

Open
thok-itx opened this issue Jul 7, 2022 · 0 comments
Open

Multiple Instances of a single Service #490

thok-itx opened this issue Jul 7, 2022 · 0 comments

Comments

@thok-itx
Copy link

thok-itx commented Jul 7, 2022

Dear BluePy Team,

I have encountered problems while extracting services from my local device. The local device is using multiple instances of the same service (e.g. Temperature) as it could perform multiple measurements.

I think this is currently not supported within the bluepy library. I tried to dig a little bit into the code. I observed that internally the services are stored within a _serviceMap that is indexed directly by the UUID:

(from bluepy/btle.py)

    def discoverServices(self):
        self._writeCmd("svcs\n")
        rsp = self._getResp('find')
        starts = rsp['hstart']
        ends   = rsp['hend']
        uuids  = rsp['uuid']
        nSvcs = len(uuids)
        assert(len(starts)==nSvcs and len(ends)==nSvcs)
        self._serviceMap = {}
        for i in range(nSvcs):
            self._serviceMap[UUID(uuids[i])] = Service(self, uuids[i], starts[i], ends[i])
        return self._serviceMap

Hence, if multiple instances exists with the same UUID, only the last instance will be reported by the bluepy library. This is also what I observed locally.

Unfortunately I don't have experience to judge if this can be changed easily. I guess it would be required to index the serviceMap with the handle of that service instead of the UUID itself, as the handle will be unique. At a fist glance, two methods would be affected if the _serviceMap would be indexed differently: def discoverServices(self): and def getServiceByUUID(self, uuidVal):.

Best Regards,
Thomas

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant