-
Notifications
You must be signed in to change notification settings - Fork 304
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
Android backend does not give each service/characteristic a unique "handle". #883
Comments
And this is the buildozer.spec file:
|
Either there is a bug with characteristic discovery, the android os hides this characteristic or the device does not have this characteristic. If we can rule out the last two, then we can look for a bug in Bleak. |
Thanks for the quick reply. The device has this characteristic (i'm 100% sure) because by launching the same code from Mac it works. What do you advise me to do? |
You could try |
Of course! I'll answer in about half an hour. I build the apk with Colab. Thank you. |
From Android Studio I see this: 2022-07-13 18:12:41.230 1983-2415/? D/BtGatt.GattService: [gattSrvHandler] msg : 3 |
This shows there is only one characteristic with handle So, to fix this, I think we need to create a mapping between a tuple containing the UUID and instance id to a "handle" integer value to be compatible with other Bleak backends. |
Thanks for the replies. However I am trying to solve the problem. 😄 |
Hi! I've tried iterating through all the features to find the one I want and then pass the instance of the characteristic itself as a char_specifier, as recommended. 2022-07-18 11:41:00.135 2008-2334/? D/BtGatt.GattService: [gattSrvHandler] msg : 2 |
How can I do to find the one I need? |
These days I have done various tests also setting the code differently but I always find only this unique characteristic "00002a00-0000-1000-8000-00805f9b34fb", which should be linked to the name of the device |
The bug in Bleak needs to be fixed. All characteristics in the dictionary are using the same key which writes over the previous key, so only the last discovered characteristic can be used currently. If Android doesn't see the characteristic at all, e.g. with the nRF Connect app, then you need to log Bluetooth packets to see what is going on. |
Thanks for the reply. I just used the nRF Connect app and my android phone sees that characteristic and the others characteristics too. |
By editing these four files and replacing them in the p4android folder I was able to remap the handles. I don't know if it's a clean result but it worked for me. |
class BleakGATTCharacteristicP4Android(BleakGATTCharacteristic):
"""GATT Characteristic implementation for the python-for-android backend"""
c = 10
def __init__(self, java, service_uuid: str, service_handle: int):
super(BleakGATTCharacteristicP4Android, self).__init__(java)
self.__uuid = self.obj.getUuid().toString()
self.__handle = self.obj.getInstanceId() + BleakGATTCharacteristicP4Android.c
#self.__handle = self.obj.getInstanceId()
logging.info('qui riga 19 characteristic.py')
logging.info(service_handle)
self.__service_uuid = service_uuid
self.__service_handle = service_handle
self.__descriptors = []
self.__notification_descriptor = None
logging.info(BleakGATTCharacteristicP4Android.c)
BleakGATTCharacteristicP4Android.c +=1 |
For example, in the characteristic.py file I made sure that an index was added to the value "self.obj.getInstanceId()" for each new service found. Because "self.obj.getInstanceId()" always returns zero for every service, characteristic handle. I don't know if it's correct but it works for me now |
what do you think of my solution? |
In #888, we discussed relaxing the |
Ok perfect I will continue to follow the updates. thank you :) |
I just now ran into similar issues. |
No definite plans. |
Description
Hello! I am trying to implement an application on an android mobile. This app needs to connect via low-energy bluetooth BLE to a scale (Mi Smart Scale 2) and take the weight. To create the apk of the application I use Colab.
The problem is that when I launch the application it crashes immediately after starting and I cannot read the weight.
What I Did
The text was updated successfully, but these errors were encountered: