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

Zephyr characteristic value update every 50ms non-blocking

Hello I'm using Zephyr and trying to update the characteristic value with interval of 50ms. The problem is that the android app nrf connect freezes after I start reading the values. The characteristic read turn off will not respond after.

I'm using k_msleep(50) which I think is blocking based on how I understand.

1. How can I update the value every 50ms with non blocking delay? Or any library for zephyr I can use? Tried looking at their samples but the led blink also uses k_msleep. Or maybe I can't find the right keyword.

2. Is updating value every 50ms just fine or too fast? 

TIA

Parents
  • k_msleep (which uses k_sleep) is not a blocking call.

    1) You can use timer and update that in the timer callback function.

    2) Depends on your connection interval. 50ms can be too small if your connection interval is closer to that value .What are the connection interval you are using and what is the max data length you are using for the packets?

  • Thank you for reply.

    1. I'll look into this.

    2. 

    BT_LE_CONN_PARAM_DEFAULT
    Default LE connection parameters: Connection Interval: 30-50 ms Latency: 0 Timeout: 4 s

    I didn't set the connection interval. Looking at the zephyr docs this one is the default which is closer or equal.  What is the lowest setting I can set the conn interval? I'm just updating an int16_t value.

    k_msleep (which uses k_sleep) is not a blocking call.

    So turn on and off notifications should function even during the duration of k_sleep?

Reply
  • Thank you for reply.

    1. I'll look into this.

    2. 

    BT_LE_CONN_PARAM_DEFAULT
    Default LE connection parameters: Connection Interval: 30-50 ms Latency: 0 Timeout: 4 s

    I didn't set the connection interval. Looking at the zephyr docs this one is the default which is closer or equal.  What is the lowest setting I can set the conn interval? I'm just updating an int16_t value.

    k_msleep (which uses k_sleep) is not a blocking call.

    So turn on and off notifications should function even during the duration of k_sleep?

Children
  • xproto said:
    I didn't set the connection interval. Looking at the zephyr docs this one is the default which is closer or equal.  What is the lowest setting I can set the conn interval? I'm just updating an int16_t value.

     When using SES you can see that for peripheral you can set few preferred connection interval like below

    For central also you can configure the min and max conn intervals through the connection management API 

     

    xproto said:
    So turn on and off notifications should function even during the duration of k_sleep?

     Not sure if i understand your question correct but the thread that has called k_sleep will be suspended for given amount of time. If you are turning on and off notifications from different thread, that will work as intended. If the notifications are turned on/off from the peer side during this k_sleep duration, then it is the LL_CONTROLLER that takes care of it, so you do not need to worry about what application threads are doing at that time

  • I'm using vscode with platformio plugin. I edited this in the conn.h since I'm not sure why when calling the function I got errors.

    This functions

    /** @brief Initialize connection parameters
     *
     *  @param int_min  Minimum Connection Interval (N * 1.25 ms)
     *  @param int_max  Maximum Connection Interval (N * 1.25 ms)
     *  @param lat      Connection Latency
     *  @param to       Supervision Timeout (N * 10 ms)
     */
    #define BT_LE_CONN_PARAM_INIT(int_min, int_max, lat, to) \
    { \
    	.interval_min = (int_min), \
    	.interval_max = (int_max), \
    	.latency = (lat), \
    	.timeout = (to), \
    }
    
    /** Helper to declare connection parameters inline
     *
     *  @param int_min  Minimum Connection Interval (N * 1.25 ms)
     *  @param int_max  Maximum Connection Interval (N * 1.25 ms)
     *  @param lat      Connection Latency
     *  @param to       Supervision Timeout (N * 10 ms)
     */
    #define BT_LE_CONN_PARAM(int_min, int_max, lat, to) \
    	((struct bt_le_conn_param[]) { \
    		BT_LE_CONN_PARAM_INIT(int_min, int_max, lat, to) \
    	 })
    


    Edited this instead

     #define BT_LE_CONN_PARAM_DEFAULT BT_LE_CONN_PARAM(BT_GAP_INIT_CONN_INT_MIN, \
    						  BT_GAP_INIT_CONN_INT_MAX, \
     						  0, 400)

    To this

    #define BT_LE_CONN_PARAM_DEFAULT BT_LE_CONN_PARAM(16, \
    						  24, \
    						  0, 400)


    Now app characteristic notif on and off on app is responsive.

    You understand it right. So that's how the k_sleep works. Thank you very much, it is clear now. I'll stick with the  k_sleep for now.

Related