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

BLE Disconnect Timeout

Hello,

How can we force a device to disconnect from a BLE Network after a certain period of inactivity (timeout) ?

Thanks.

Parents
  • There is nothing internally in softdevice or SDK drivers that will detect this inactivity. Your application have to detect this by itself. It can for example start a 10 second timer which has to be reset everytime there is data write is done. So when it expires it means that no data has been transferred in the last 10 seconds. The downside is that this will only work for writes, if you want notifications or other procedures to count as activity, you have to reset the timer at those places.

    There is a lot of traffic between two controllers in connection that are not notified to the application. If you use timers that traffic will be considered as inactivity. There is no other way that I can think of right now.

  • using app_timer library

    static void timers_init(void)
    {
    
        // Initialize timer module.
        APP_TIMER_INIT(0, APP_TIMER_MAX_TIMERS, APP_TIMER_OP_QUEUE_SIZE, false);
    
        // Create timers.
    
    
        uint32_t err_code;
        err_code = app_timer_create(&m_app_timer_id, APP_TIMER_MODE_REPEATED, timer_timeout_handler);
        APP_ERROR_CHECK(err_code);
    }
    
    void start_timer()
    {
        uint32_t err_code;
        err_code = app_timer_start(m_app_timer_id, 10 * 32768, NULL);  // handler timer_timeout_handler will be called every 10 seconds unless stopped
        APP_ERROR_CHECK(err_code);
    }
    
    void stop_timer()
    {
        uint32_t err_code;
        err_code= app_timer_stop(m_app_timer_id);
        APP_ERROR_CHECK(err_code);  }
    
    void reset_timer()
    {
      stop_timer();
      start_timer();
    }
    
Reply
  • using app_timer library

    static void timers_init(void)
    {
    
        // Initialize timer module.
        APP_TIMER_INIT(0, APP_TIMER_MAX_TIMERS, APP_TIMER_OP_QUEUE_SIZE, false);
    
        // Create timers.
    
    
        uint32_t err_code;
        err_code = app_timer_create(&m_app_timer_id, APP_TIMER_MODE_REPEATED, timer_timeout_handler);
        APP_ERROR_CHECK(err_code);
    }
    
    void start_timer()
    {
        uint32_t err_code;
        err_code = app_timer_start(m_app_timer_id, 10 * 32768, NULL);  // handler timer_timeout_handler will be called every 10 seconds unless stopped
        APP_ERROR_CHECK(err_code);
    }
    
    void stop_timer()
    {
        uint32_t err_code;
        err_code= app_timer_stop(m_app_timer_id);
        APP_ERROR_CHECK(err_code);  }
    
    void reset_timer()
    {
      stop_timer();
      start_timer();
    }
    
Children
No Data
Related