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 !

  • Hi ,

    Here are my parameters :

    #define APP_ADV_INTERVAL                400                                         /**< The advertising interval (in units of 0.625 ms. This value corresponds to 250 ms). */
    
    #define MIN_CONN_INTERVAL               BLE_GAP_CP_MIN_CONN_INTVL_MIN           /**< Minimum acceptable connection interval (0.1 seconds). */
    #define MAX_CONN_INTERVAL               BLE_GAP_CP_MAX_CONN_INTVL_MIN            /**< Maximum acceptable connection interval (0.2 second). */
    #define SLAVE_LATENCY                   0                                           /**< Slave latency. */
    #define CONN_SUP_TIMEOUT                MSEC_TO_UNITS(4000, UNIT_10_MS)             /**< Connection supervisory timeout (4 seconds). */
    
    #define FIRST_CONN_PARAMS_UPDATE_DELAY  APP_TIMER_TICKS(20000)                   /**< Time from initiating event (connect or start of notification) to first time sd_ble_gap_conn_param_update is called (5 seconds). */
    #define NEXT_CONN_PARAMS_UPDATE_DELAY   APP_TIMER_TICKS(5000)                      /**< Time between each call to sd_ble_gap_conn_param_update after the first call (30 seconds). */
    #define MAX_CONN_PARAMS_UPDATE_COUNT    3                                           /**< Number of attempts before giving up the connection parameter negotiation. */

    Feel free to ask me if you meant other parameters.

    Thanks for your help !

  • Are BLE_GAP_CP_MIN_CONN_INTVL_MIN and BLE_GAP_CP_MAX_CONN_INTVL_MIN what the comments state 100ms and 200ms? In that case the problem is likely that your application sends notification inbetween and during connection intervals. You should decrease these to lower values. I.E. 10 and 30 ms, to make sure that your device is able to connect before sending the notify 

    Did you have any luck looking into the GitHub example I linked to?

    Best regards,

    Simon

  • Do not pay attention to the comments they may not be right !

    BLE_GAP_CP_MIN_CONN_INTVL_MIN and BLE_GAP_CP_MAX_CONN_INTVL_MIN are standard for me, so they refer to ble_gap.h :

    #define BLE_GAP_CP_MIN_CONN_INTVL_MIN            0x0006  /**< Lowest minimum connection interval permitted, in units of 1.25 ms, i.e. 7.5 ms. */
    
    #define BLE_GAP_CP_MAX_CONN_INTVL_MIN            0x0006  /**< Lowest maximum connection interval permitted, in units of 1.25 ms, i.e. 7.5 ms. */

    So in your opinion my min connection interval should be 10ms and my max 30ms ?

    In my case I have 7.5ms for both min and max and this could be the issue ?

    Yes I checked the Github but not tested yet. If I can resolve this issue with the connection parameters it would be a huge advantage so I prefer to explore this path first :)

  • Hi

    It should be fine having set the connection interval to 7.5ms, however this is on the peripheral side, which the central side doesn't have to "agree" with. Are you able to find the central side connection intervals? If you have a log with timestamps for example, you'll be able to see how long the device actually uses to connect.

    For most Android phones the minimum connection interval is 25ms or so (30ms for iPhones), which is cutting it close to your notification interval of 30ms. I suspect you might have to increase the notification interval somewhat to make this compatible to any device.

    Best regards,

    Simon

  • Hi !

    So according to what you say, if I understand correctly, do you think that if I change my notification timer from 30ms to 20ms for example this can avoid this unwanted behavior ?

    I will take a look at the central side but this is standard as far as I know for my Android and MacBook.

Related