Can the callbacks generated by subscribing to notifications last forever #658
Replies: 4 comments
-
What event should trigger the program to end? For example, maybe the program should end when the device disconnects. The you can use |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
I want to always subscribe to notifications and be able to always receive callbacks to process my data, but after subscribing only through await client.start_notify(CHARACTERISTIC_UUID, notification_handler), I can only receive notifications once and never receive them again. I didn’t call start_stop, nor did I call it unless the device was disconnected。 async def run(self,debug=0):
log = logging.getLogger(__name__)
if debug:
import sys
async with BleakClient(self.bleMac) as self.client:
x = await self.client.is_connected()
keyuu = '6e'
for service in self.client.services:
print(service.uuid)
if keyuu not in service.uuid:
continue
for char in service.characteristics:
print(char.properties)
if 'notify' not in char.properties:
continue
else:
print(char.uuid)
self.noticeuuid = char.uuid
try:
value = bytes(await self.client.read_gatt_char(char.uuid))
except Exception as e:
value = str(e).encode()
for descriptor in char.descriptors:
value = await self.client.read_gatt_descriptor(descriptor.handle)
# await asyncio.sleep(1)
#await self.client.stop_notify(CHARACTERISTIC_UUID)
# while(True):
await self.client.start_notify(self.noticeuuid,self.notification_handler) |
Beta Was this translation helpful? Give feedback.
-
Hello, what should I do to keep being notified at all times? Or is there an example for reference? |
Beta Was this translation helpful? Give feedback.
-
while(True): await self.client.start_notify(self.noticeuuid, notification_handler())
while(true)
to always enable notification. Is there a better way?while(true)
. My Bluetooth is sent once a second, but when I print the time in the notification_handler callback, I find that notice is not called strictly in 1 second? How to solve it?Beta Was this translation helpful? Give feedback.
All reactions