This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Update characteristic value only on characteristic read?

Other Parts Discussed in Thread: CC2650, CC2560

I am trying to implement a battery level characteristic, but to save power I'd like to only read the battery level when a read request is issued to the characteristic.

Is it possible to detect when the characteristic is read, perform a task, then update the values before it is sent to the client?

If this isn't possible, what other periodic bluetooth events might I be able to use to update the battery characteristic? I want to avoid doing it with a timer so that I can keep the device (CC2650) in a low power mode.

Right now I'm building my app around the project zero example on the cc2560 launchpad

  • Hi ,

    yes, you can update such value when characteristic read.

    About the other question, you can simply put a very high period for "performPeriodicTask()" just like, I don't know, 1800000 for half an hour. This will barely affect your consumption. I do this every hour with no problem. Just remember to start the clock in "init()" instead of when a connection takes place as in the code from TI.

    Bye.
  • Hi Craig,

    As long as the update is fast, you can grab the value and send it over BLE. Is issue here is you're still in the stack context when simpleProfile_ReadAttrCB is called. A value must be copied over within a specified time or issues can occur in the stack.

    Anyway - there's other methods to do what you're asking - here's a scenario:

    You have a Peripheral with a characteristic that has a CCCD that allows notifications. You can have a central device (a phone) write to the cccd to register for notifications. Your application will get notified that the registration occurred. In the application context go ahead and start processing, and once complete, send the notification asynchronously. Avoiding timers all together.

    You should have all the information you need to do this in Simple Link Academy and project zero.

    Regards,

    -Rebel
  • @kazola, Will this cause any issues with power modes?