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

Start/Stop Timer with notifications and connection status

In Short: How to get status wether noticiations are enabled or not? Where is this stored?

Hello,

I would like my peripheral to start/stop a timer that does measurements and sends them via sd_ble_gatts_hvx(m_conn_handle,&hvx_params); based on notificaions enabled and connection status.. in other words:

Start Timer when connected and notifications are enabled Stop Timer when disconnected. No matter if notifications are enabled.

But of course on reconnection the notifications are still enabled and therefore the timer shall be started again.

The missing part is to start the timer after connection_evt but only when notifications are enabled. How can I realize this?

Search gave me this thread, but it won't help in this case. I found a ble_srv_is_notification_enabled function inside ble_conn_params.c that looks promising. How can I use this in my main?

Of course I got it working using a workaround (set notf_enabled? flag based on write.data). But I'd prefer a straight forward solution

  • @muhkuhns : From the thread you linked only option 1 is not relevent because you don't want to actually send notification.

    But option 2- wait for the BLE_GATTS_EVT_WRITE and detect if it is a write command to enable notification to start the timer and option 3- read the cccd characteristic to see if it is enabled to start timer

    are fine and straight forward for your application, I don't see any reason why they are not.

Related