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

Update timer speed once connected

I have a custom Characteristic in my GATT that is sending data in Notify mode every 30ms.

In my firmware I use timer to do this with something like this :


#define RTC1_TICK_DURATION		31
	
#define TIMER_ONE_DURATION   		33 // 30ms																/**<(deflt:1000)[ms] sending/measurement cycle duration for 1s cycled characteristics*/
#define TIMER_ONE_TICKS_NB 		(TIMER_ONE_DURATION * 1000 / RTC1_TICK_DURATION)


err_code = app_timer_start(m_TimerOne_id, (uint32_t)TIMER_ONE_TICKS_NB, NULL);


Everything is working great but sometimes, randomly, my app using BLE or my laptop using Web BLE (so two different device with two different source code with the same behavior) are unable to retrieve value for this Characteristic. They are able to connect to my device but no Characteristic value is send.

I tried to change the interval from 30ms to 90ms and so far I am not able to reproduce this issue so it lead me to think that the speed can be the source of the issue.

How would you deal with that ? Is it possible to notify at a low pace, then one second after a connection is made, increase the speed ? Or better, when someone subscribe to the Notifying Characteristic increase speed, when it disconnect decrease speed ?

Thanks !

  • No, I think you might have to make the number bigger than 30ms. As the application has to be able to connect before the notification is sent. Have you tried with any interval values between 30 and 90ms?

    Best regards,

    Simon

  • Ok I will try other value for example 35ms and 50ms and let you know here. Even if this is not a solution because I cannot go slower than 30ms for my notification.

  • I performed new test just by changing the TIMER_ONE_DURATION value. I tried with values 99, 66, 40, 35, 33, 25.

    In all cases, in opposition to what I stated in my first post, it fails after an average of 3 tries.

    But it's not a connection issue, because in all cases, I succeed to connect to the device. It's just that I do not succeed to subscribe to the notification after connecting to my device.

  • As an illustration, here is what my device looks like when it's working, I'm connected and I see value on my Characteristic :

    Exact same code, after few tries, here is what it look like. I'm connected but this time I see no value on my Characteristic :

  •  do not pay attention to my previous answer about changing the TIMER_ONE_DURATION. I was changing the wrong timer........

    I tested again this morning, when I set the timer to 35 it failed after 7 tries.

    I tested with a timer 40, after 20 tries it did not failed.

    Now my timer is set to 25.

    One new thing, to check if the issue is coming from the timer (maybe not started or whatever), I set a value to 0 after a new connection then in my timer condition, I increase this value and I send it in my Characteristic.

    Now I read this value before subscribing to the Notification then I subscribe to my Characteristic.

    When everything is working great the first time I read the value I get approximately 27 every time, so a little bit less than one second between the connection is made and just before the subscription. After the subscription I see the value increasing as the timer is fired and my subscription to the notification is successfully made.

    But when it's not working, the value is not 27 but usually 54 (so exactly the double). And the subscription to notification is not working.

    Now when it's not working, I read again the value, and this is the exact same value I get. This make me think that the timer is not fired anymore. Could this be because it's started twice at the same time or something like that and it crash ?

    Here is an illustration of when it's working and when it's not working on the console.

    ---

    EDIT : could this be the same issue ? https://devzone.nordicsemi.com/f/nordic-q-a/9179/app_timer-triggering-twice I don't understand exactly how to fix this and where to put delay.

Related