Arm Mbed OS support forum

Change BLE connection interval

Hi all

I am using the mbed heartrate example on mbed (with nrf52_EK) and I was trying to change the BLE connection interval (let’s say to the minimum - 7.5ms) to perform some tests.

A piece of code I found online is the following
but It gives erros and doesn’t compile…

Any solutions or suggestions?

best!

void updateConnectionParams()
{
    BLE &ble = BLE::Instance();
    if (ble.getGapState().connected) {
        gap_params.connectionSupervisionTimeout = 500;
        gap_params.minConnectionInterval = 6; // It is unit of 1.25 ms
        gap_params.maxConnectionInterval = 6;
        gap_params.slaveLatency = 0;
 
        LOG("Request a connection params update!\n");
        if (ble.gap().updateConnectionParams(gap_h, &gap_params) != BLE_ERROR_NONE) {
            LOG("Error sending the request!\n");
        }
    }
}

@mreiscarneiro Here is an example code I have used in the past so I can update the connection parameter when an IPhone connects to my BLE Device.

//iphones connection intervals.
const uint16_t MinConnectionInterval = 512; 
const uint16_t MaxConnectionInterval = 532;
const uint16_t SlaveLatency = 2;
const uint16_t ConnectionSupervisionTimeout = 600;

void BleDongle::UpdateConnectionParameter() {
    if(m_bIsConnected) {
        //update the connection parameters to set better power management.
        ble_error_t error = m_ble.gap().updateConnectionParameters(m_nConnectionHandle,
                                    ble::conn_interval_t(ble::conn_interval_t(MinConnectionInterval)),
                                    ble::conn_interval_t(ble::conn_interval_t(MaxConnectionInterval)),
                                    ble::slave_latency_t(SlaveLatency),
                                   ble::supervision_timeout_t(ble::supervision_timeout_t(ConnectionSupervisionTimeout)));
                                    
        if(error != BLE_ERROR_NONE) {
            logError("Unable to Update connection parameters with BLE Error: %d\n", error);
        }
        else {
            logDebug("Updated Connection Parameters successfully!!!");
        }
    }
} 

Thanks,
Ajay