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

Why status code BLE_HCI_CONN_FAILED_TO_BE_ESTABLISHED ?

I'm tring to connect my phone to the multi-connect example client app

I'm tracing the ble events in the ble_evt_handler.

When I open the server app on my phone, I see this in my RTT

BLE_GAP_EVT_CONNECTED
BLE_GAP_EVT_DISCONNECTED
BLE_GAP_EVT_CONNECTED
BLE_GAP_EVT_DISCONNECTED
BLE_GAP_EVT_CONNECTED
BLE_GAP_EVT_DISCONNECTED
...

like the phone is connecting, advertising, and reconnecting over and over...

The when I go BLE_GAP_EVT_DISCONNECTED case statement and print reason for discconnect I get

BLE_HCI_CONN_FAILED_TO_BE_ESTABLISHED   0x3E

So I think well why is BLE_GAP_EVT_CONNECTED true if device never connected in the first place according to BLE_HCI_CONN_FAILED_TO_BE_ESTABLISHED?

So then I think maybe there is difference between being connected and establishing a connection?

In the Android code, I've chaned the device name to Nordic_Blinky; therefore the multi-connect client should connect to the Android server right? The Android phone is advertising a Time service, but I don't think that matters here right?

I just can't think of a reason why the phone connects, but the connection fails to be established or what that even means.

Here is my Android startServer method

/**
 * Initialize the GATT server instance with the services/characteristics
 * from the Time Profile.
 */
private void startServer() {
    mBluetoothGattServer = mBluetoothManager.openGattServer(this, mGattServerCallback);
    if (mBluetoothGattServer == null) {
        Log.w(TAG, "Unable to create GATT server");
        return;
    }

    mBluetoothGattServer.addService(TimeProfile.createTimeService());
    
    // Initialize the local UI
    updateLocalUi(System.currentTimeMillis());
}

And here is startAdvertising method

/**
 * Begin advertising over Bluetooth that this device is connectable
 * and supports the Current Time Service.
 */
private void startAdvertising() {
    BluetoothAdapter bluetoothAdapter = mBluetoothManager.getAdapter();
    mBluetoothLeAdvertiser = bluetoothAdapter.getBluetoothLeAdvertiser();
    if (mBluetoothLeAdvertiser == null) {
        Log.w(TAG, "Failed to create advertiser");
        return;
    }

    AdvertiseSettings settings = new AdvertiseSettings.Builder()
            .setAdvertiseMode(AdvertiseSettings.ADVERTISE_MODE_BALANCED)
            .setConnectable(true)
            .setTimeout(0)
            .setTxPowerLevel(AdvertiseSettings.ADVERTISE_TX_POWER_MEDIUM)
            .build();

    boolean isNameChanged = BluetoothAdapter.getDefaultAdapter().setName("Nordic_Blinky");
    if(isNameChanged) Log.d(TAG,"Device name changed successfully.");

    AdvertiseData data = new AdvertiseData.Builder()
            .setIncludeDeviceName(true)
            .setIncludeTxPowerLevel(false)
            .addServiceUuid(new ParcelUuid(TimeProfile.TIME_SERVICE))
            .build();

    mBluetoothLeAdvertiser
            .startAdvertising(settings, data, mAdvertiseCallback);
}
Related