https://toitlang.org/ logo
BLE GATT Subscription, using Monitors or Tasks
# help
z
I have to do some reading from 2 separate BLE GATT subscriptions. One of the subscriptions emits a value once per second (onehertz) One emits values at a near constant stream - like 60 Hz (sixtyhertz) I'm considering using Tasks to have one "thread" running the onehertz loop, and another running the sixtyhertz loop. Can BLE connections be passed around to multiple Tasks? Can I instantiate the subscription in the main loop and then reference that subscription in a Task?
i
you can create the characteristics which are used by the service like so for example:
command-charac = service.add-write-only-characteristic COMMAND-CHARAC-UUID
and then you can run one or multiple tasks like so:
Copy code
command-receiver-task:
  while true:
    payload := command-charac.read
    ...
which will handle the reads whenever something was written to that characteristic
I hope this was what you are asking for. You can then also use a channel from toit to receive the data somewhere else
f
Tasks are cooperative threads sharing memory. You can pass objects between them.
2 Views