为什么BLE外设与NRF连接应用断开连接?

时间:2018-09-01 04:39:11

标签: java android bluetooth-lowenergy bluetooth-peripheral

private final BluetoothGattServerCallback mGattServerCallback = new BluetoothGattServerCallback() {
@Override
public void onConnectionStateChange(BluetoothDevice device, final int status, int newState) {
  super.onConnectionStateChange(device, status, newState);
  if (status == BluetoothGatt.GATT_SUCCESS) {
    if (newState == BluetoothGatt.STATE_CONNECTED) {
      mBluetoothDevices.add(device);
      updateConnectedDevicesStatus();
      String macAddress = android.provider.Settings.Secure.getString(getApplication().getContentResolver(), "bluetooth_address");
      Log.v(TAG, "Connected to device: " + device.getAddress());
      Log.d("/bleUUID","uuid is " +macAddress);
      Log.d("/bleUUID","uuid is " +CHARACTERISTIC_USER_DESCRIPTION_UUID);
    } else if (newState == BluetoothGatt.STATE_DISCONNECTED) {
      mBluetoothDevices.remove(device);
      updateConnectedDevicesStatus();
      Log.v(TAG, "Disconnected from device");
    }
  } else {
    mBluetoothDevices.remove(device);
    updateConnectedDevicesStatus();
    // There are too many gatt errors (some of them not even in the documentation) so we just
    // show the error to the user.
    final String errorMessage = getString(com.efftronics.android.bleperipheral.R.string.status_errorWhenConnecting) + ": " + status;
    runOnUiThread(new Runnable() {
      @Override
      public void run() {
        Toast.makeText(Peripheral.this, errorMessage, Toast.LENGTH_LONG).show();
      }
    });
    Log.e(TAG, "Error when connecting: " + status);
  }
}
}

从nrf connect断开连接时,此onConnectionStateChange未调用。为什么?

我正在实现BLE外围应用程序。我的应用是广告(外围模式)。 NRF连接(中央模式)正在扫描广告设备。

当另一个应用程序连接到我的ble外围应用程序时,我的ble围产期应用程序的地址显示在NRF connect中。该地址来自此行。

  

私有静态最终UUID CHARACTERISTIC_USER_DESCRIPTION_UUID = UUID         .fromString(“ 00002901-0000-1000-8000-00805f9b34fb”);

但是每次连接到NRF连接时,此地址都会更改。为什么?

如果我每次都需要相同的地址。我该怎么办?

一段时间后,我的外围设备应用程序会自动断开连接,并显示超时错误。为什么?

请帮助我。任何帮助将不胜感激。this is my ble peripheral app which is advertising.

This is other app which is  scanning for the devices and connected to my peripheral app(installed in lenovo tab). And here showing some address like 58:31:8F:FF:56:AB. If I disconnect my peripheral app and again reconnected then this address is changing every time

This error is coming in the nrFConect app(central). Why it is coming?

0 个答案:

没有答案