Мне нужно пройти аутентификацию на устройстве BLE, для которого требуется ключ> SBIK12345 <прежде всего.Я не могу написать какую-либо характеристику и услугу без ключа. </p>
Какая идея?
Это мой метод подключения (из этого репозитория BluLeGatt от Anlif )
public boolean connect(final String address)
{
if (mBluetoothAdapter == null || address == null)
{
System.out.println(TAG+"BluetoothAdapter not initialized or unspecified address.");
return false;
}
// Previously connected device. Try to reconnect.
if (mBluetoothDeviceAddress != null && address.equals(mBluetoothDeviceAddress)
&& mBluetoothGatt != null)
{
System.out.println(TAG+"Trying to use an existing mBluetoothGatt for connection.");
if (mBluetoothGatt.connect()) {
mConnectionState = STATE_CONNECTING;
return true;
} else {
return false;
}
}
final BluetoothDevice device = mBluetoothAdapter.getRemoteDevice(address);
if (device == null)
{
System.out.println(TAG+"Device not found. Unable to connect.");
return false;
}
// We want to directly connect to the device, so we are setting the autoConnect
// parameter to false.
try
{
device.createInsecureRfcommSocketToServiceRecord(UUID.fromString(SampleGattAttributes.UUID_BLE_080));
}
catch (IOException e)
{
System.out.println("exc createInsecureRfcommSocketToServiceRecord "+e.getLocalizedMessage());
}
mBluetoothGatt = device.connectGatt(this, true, mGattCallback);
System.out.println(TAG+" Trying to create a new connection.");
BluetoothGattCharacteristic characteristic1 = new BluetoothGattCharacteristic(UUID.fromString(SampleGattAttributes.UUID_BLE_080),BluetoothGattCharacteristic.WRITE_TYPE_NO_RESPONSE,BluetoothGattCharacteristic.WRITE_TYPE_NO_RESPONSE);
characteristic1.setValue(">SBIK1234<");
mBluetoothGatt.writeCharacteristic(characteristic1);
mBluetoothDeviceAddress = address;
mConnectionState = STATE_CONNECTING;
return true;
}
И статическая переменная
public static String UUID_BLE_080 = "00000000-dc70-0080-dc70-a07ba85ee4d6";