正在修改BluetoothLeGatt以发出Jaalee信标的声音。能够连接到信标,但不能绑定以写出信标的特征。借助NRF Connect和BLE扫描仪,我能够将密码特征写入绑定并将特征写入声音。可以肯定的是,我修改后的BluetoothLeGatt的问题在于它没有将密码0x666666写到信标,因为如果我第一次与NFR connect或BLE扫描仪绑定,我可以使信标在修改后的BluetoothLeGatt上发出声音。
我尝试了不同形式的密码fff 666666。
// service sound
public void onClickWrite(View v){
if(mBluetoothLeService != null) {
mBluetoothLeService.writeCustomCharacteristic(0x02);
}
}
// service login
public void onClickLogin(View v){
if(mBluetoothLeService != null) {
mBluetoothLeService.LoginCustomCharacteristic(0x666666);
}
}
// activity sound
public void writeCustomCharacteristic(int value) {
if (mBluetoothAdapter == null || mBluetoothGatt == null) {
Log.w(TAG, "BluetoothAdapter not initialized");
return;
}
/*check if the service is available on the device*/
BluetoothGattService mCustomService = mBluetoothGatt.getService(UUID.fromString("00001802-0000-1000-8000-00805f9b34fb"));
if(mCustomService == null){
Log.w(TAG, "Custom BLE Service not found");
return;
}
/*get the read characteristic from the service*/
BluetoothGattCharacteristic mWriteCharacteristic = mCustomService.getCharacteristic(UUID.fromString("00002a06-0000-1000-8000-00805f9b34fb"));
mWriteCharacteristic.setValue(value,android.bluetooth.BluetoothGattCharacteristic.FORMAT_UINT8,0);
if(mBluetoothGatt.writeCharacteristic(mWriteCharacteristic) == false){
Log.w(TAG, "Failed to write characteristic");
}
}
// activity login
public void LoginCustomCharacteristic(int value) {
if (mBluetoothAdapter == null || mBluetoothGatt == null) {
Log.w(TAG, "BluetoothAdapter not initialized");
return;
}
/*check if the service is available on the device*/
BluetoothGattService mCustomService = mBluetoothGatt.getService(UUID.fromString("0000fff0-0000-1000-8000-00805f9b34fb"));
if(mCustomService == null){
Log.w(TAG, "Custom BLE Service not found");
return;
}
/*get the read characteristic from the service*/
BluetoothGattCharacteristic mWriteCharacteristic = mCustomService.getCharacteristic(UUID.fromString("0000fff1-0000-1000-8000-00805f9b34fb"));
mWriteCharacteristic.setValue(value,android.bluetooth.BluetoothGattCharacteristic.FORMAT_UINT8,0);
if(mBluetoothGatt.writeCharacteristic(mWriteCharacteristic) == false){
Log.w(TAG, "Failed to write characteristic");
}