This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Best way to set up multiple timers for respective services?

I'm trying to set up a system where the sample rate of data being notified to the client from various sensors can be changed by updating a configuration characteristic in that service.

What I have right now is one service, holding a data characteristic and a sample rate characteristic. I can receive data back to the client just now at an interval, and set the value of the sample rate characteristic, but it doesn't modify the timer yet. My project is based off the custom service and characteristic tutorials.

What would be the best way to implement a timer that is tied to the service in a way that it's prescaler/timeout value can be modified? I would also intend to have various other services with their own timers so it would be good to find a solution that can scale.

Parents
  • If you need several timers (as is the case for most real applications) you should consider the application timer library. It user the RTC1 peripheral to create as many independent timers as needed. The documentation is fairly good, and there is also a tutorial which explains all the basic concepts.

    In order to update the sampling rate you would then write to the sampling rate characteristing via BLE. The value will be updated by the SoftDevice, and your application will receive an BLE_GATTS_EVT_WRITE event. If the sampling rate has changed, you can then update the timer by stopping and starting it again with a new timeout value. Alternatively (and perhaps more elegantly) you could flag that a update is needed, and update the timer the next time it times out.

  • It's better if you create a new question instead of the question in your last comment, as it is unrelated to the original question. This way it is more likely that the question and answer will be easier to find for others with similar problems.

Reply Children
No Data
Related