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

Quick connection parameters update

Hello everyone,

I'm currently trying to change the connection parameters to be quick(100ms 0 slave latency) on a button press and after a timer timeout I go back to the low connection parameters.

I'm also sending a notification to an android application at the same time and then send back 2 characteristic ( LED toggle and a string for a LCD) .

It's working but it take quite a long time (10s) for my application to change the connection parameters so the 2 characteristic are not sent at quick connection parameters the first time but if I press a second time it's then updated and send it quickly.

Do you guys know a workaround this problem ?

Parents
  • This is my timer handler

       static void cp_timeout_handler(void * p_context) {
    	UNUSED_PARAMETER(p_context);
    
    		gap_params_low();}
    

    Those are the funstion that send the new parameters

    static void gap_params_high(void) {
    	ble_gap_conn_params_t gap_conn_params_high;
        gp=false;
    	memset(&gap_conn_params_high, 0, sizeof(gap_conn_params_high));
    
    	gap_conn_params_high.min_conn_interval = MIN_CONN_ITVL_UPDATE;
    	gap_conn_params_high.max_conn_interval = MAX_CONN_ITVL_UPDATE;
    	gap_conn_params_high.slave_latency = SLAVE_LATENCY_UPDATE;
    	gap_conn_params_high.conn_sup_timeout = CONN_SUP_TIMEOUT_UPDATE;
    
    	ble_conn_params_change_conn_params(&gap_conn_params_high);
    			
    
    
    }
    static void gap_params_low(void) {
    	ble_gap_conn_params_t gap_conn_params_low;
    
    	gp=true;
    	memset(&gap_conn_params_low, 0, sizeof(gap_conn_params_low));
    
    		gap_conn_params_low.min_conn_interval = MIN_CONN_INTERVAL;
    		gap_conn_params_low.slave_latency = SLAVE_LATENCY;
    		gap_conn_params_low.conn_sup_timeout = CONN_SUP_TIMEOUT;
    	ble_conn_params_change_conn_params(&gap_conn_params_low);
    
    			
    
    
    }
    

    This is my case in on_ble_evt

    case BLE_GAP_EVT_CONN_PARAM_UPDATE:
    		
    		app_timer_start(m_cp_timer_id, CP_INTERVAL,
    						NULL);
    
    			break;
    

    This is my button handler

    static void button_event_handler(uint8_t pin_no, uint8_t button_action) {
    	
         app_timer_stop(m_powermanage_timer_id);
             if (gp){
    		gap_params_high();
    	          }
    
    
    
    	/*Joue le son du Buzzer*/
    	set_frequency_and_duty_cycle((uint32_t) (1075), 50);
    	nrf_delay_ms(300);
    	nrf_pwm_set_enabled(0);
    
    	switch (pin_no) {
    	case BOUTON_SONNETTE_PIN_NO:
    
    
                    ble_lbs_on_button_change(&m_lbs,button_action);
    
    		nrf_gpio_pin_write(LED_LCD_PIN, 1);
    
    		gotoXY(12,2);
    		LCDString("Bienvenue",1);
    
    		break;
    
    
    	default:
    
    		break;
    	}
    
    app_timer_start(m_powermanage_timer_id, POWER_MANAGE_INTERVAL,
    				NULL);
    gp=false;
    pm=false;}
    

    gp is a static bool that I use because the event handler is called 2 times ( on push and release)

    pm is also a static bool that I use to not go into power manage as long as the smartphone send write(in the handler of some characteristics)

Reply
  • This is my timer handler

       static void cp_timeout_handler(void * p_context) {
    	UNUSED_PARAMETER(p_context);
    
    		gap_params_low();}
    

    Those are the funstion that send the new parameters

    static void gap_params_high(void) {
    	ble_gap_conn_params_t gap_conn_params_high;
        gp=false;
    	memset(&gap_conn_params_high, 0, sizeof(gap_conn_params_high));
    
    	gap_conn_params_high.min_conn_interval = MIN_CONN_ITVL_UPDATE;
    	gap_conn_params_high.max_conn_interval = MAX_CONN_ITVL_UPDATE;
    	gap_conn_params_high.slave_latency = SLAVE_LATENCY_UPDATE;
    	gap_conn_params_high.conn_sup_timeout = CONN_SUP_TIMEOUT_UPDATE;
    
    	ble_conn_params_change_conn_params(&gap_conn_params_high);
    			
    
    
    }
    static void gap_params_low(void) {
    	ble_gap_conn_params_t gap_conn_params_low;
    
    	gp=true;
    	memset(&gap_conn_params_low, 0, sizeof(gap_conn_params_low));
    
    		gap_conn_params_low.min_conn_interval = MIN_CONN_INTERVAL;
    		gap_conn_params_low.slave_latency = SLAVE_LATENCY;
    		gap_conn_params_low.conn_sup_timeout = CONN_SUP_TIMEOUT;
    	ble_conn_params_change_conn_params(&gap_conn_params_low);
    
    			
    
    
    }
    

    This is my case in on_ble_evt

    case BLE_GAP_EVT_CONN_PARAM_UPDATE:
    		
    		app_timer_start(m_cp_timer_id, CP_INTERVAL,
    						NULL);
    
    			break;
    

    This is my button handler

    static void button_event_handler(uint8_t pin_no, uint8_t button_action) {
    	
         app_timer_stop(m_powermanage_timer_id);
             if (gp){
    		gap_params_high();
    	          }
    
    
    
    	/*Joue le son du Buzzer*/
    	set_frequency_and_duty_cycle((uint32_t) (1075), 50);
    	nrf_delay_ms(300);
    	nrf_pwm_set_enabled(0);
    
    	switch (pin_no) {
    	case BOUTON_SONNETTE_PIN_NO:
    
    
                    ble_lbs_on_button_change(&m_lbs,button_action);
    
    		nrf_gpio_pin_write(LED_LCD_PIN, 1);
    
    		gotoXY(12,2);
    		LCDString("Bienvenue",1);
    
    		break;
    
    
    	default:
    
    		break;
    	}
    
    app_timer_start(m_powermanage_timer_id, POWER_MANAGE_INTERVAL,
    				NULL);
    gp=false;
    pm=false;}
    

    gp is a static bool that I use because the event handler is called 2 times ( on push and release)

    pm is also a static bool that I use to not go into power manage as long as the smartphone send write(in the handler of some characteristics)

Children
Related