guild icon
Toit
#BLE GATT Subscription, using Monitors or Tasks
Thread channel in help
z3ugma
z3ugma 04/22/2024 05:47 PM
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?
theHuanter
theHuanter 04/22/2024 09:06 PM
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:
command-receiver-task: while true: payload := command-charac.read ...
which will handle the reads whenever something was written to that characteristic
theHuanter
theHuanter 04/22/2024 09:07 PM
I hope this was what you are asking for. You can then also use a channel from toit to receive the data somewhere else
z3ugmaOPz3ugma
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 -...
floitsch
floitsch 04/22/2024 09:40 PM
Tasks are cooperative threads sharing memory. You can pass objects between them.
4 messages in total