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.

  • That's good to know, I was gonna use the various other timers but this helps.

    My question was more about how to go about implementing them within the services though and modifying the prescalers based on characteristic values.

    In the example I have the implementation of the timer is at the top level in main.c, but if I want to change it based on the service characteristic, how would I go about this in a scalable manner if I had various services? Perhaps this is more of a software structure question...

Reply
  • That's good to know, I was gonna use the various other timers but this helps.

    My question was more about how to go about implementing them within the services though and modifying the prescalers based on characteristic values.

    In the example I have the implementation of the timer is at the top level in main.c, but if I want to change it based on the service characteristic, how would I go about this in a scalable manner if I had various services? Perhaps this is more of a software structure question...

Children
No Data
Related