在android中,通过BLE发送数据必须使用哪些服务和特性?
我开发了一个Android应用程序,可以将数据发送到BLE设备。当我连接到BLE设备时,我发现了服务和特性,并得到了这些在android中,通过BLE发送数据必须使用哪些服务和特性?,android,bluetooth-lowenergy,android-ble,Android,Bluetooth Lowenergy,Android Ble,我开发了一个Android应用程序,可以将数据发送到BLE设备。当我连接到BLE设备时,我发现了服务和特性,并得到了这些 onGetService() - Device=D8:80:39:F0:03:6E UUID=00001800-0000-1000-8000-00805f9b34fb onGetService() - Device=D8:80:39:F0:03:6E UUID=0000180a-0000-1000-8000-00805f9b34fb onGetService() - Devi
onGetService() - Device=D8:80:39:F0:03:6E UUID=00001800-0000-1000-8000-00805f9b34fb
onGetService() - Device=D8:80:39:F0:03:6E UUID=0000180a-0000-1000-8000-00805f9b34fb
onGetService() - Device=D8:80:39:F0:03:6E UUID=49535343-fe7d-4ae5-8fa9-9fafd205e455
onGetCharacteristic() - Device=D8:80:39:F0:03:6E UUID=00002a00-0000-1000-8000-00805f9b34fb
onGetCharacteristic() - Device=D8:80:39:F0:03:6E UUID=00002a01-0000-1000-8000-00805f9b34fb
onGetCharacteristic() - Device=D8:80:39:F0:03:6E UUID=00002a04-0000-1000-8000-00805f9b34fb
onGetCharacteristic() - Device=D8:80:39:F0:03:6E UUID=00002a29-0000-1000-8000-00805f9b34fb
onGetCharacteristic() - Device=D8:80:39:F0:03:6E UUID=00002a24-0000-1000-8000-00805f9b34fb
onGetCharacteristic() - Device=D8:80:39:F0:03:6E UUID=00002a25-0000-1000-8000-00805f9b34fb
onGetCharacteristic() - Device=D8:80:39:F0:03:6E UUID=00002a27-0000-1000-8000-00805f9b34fb
onGetCharacteristic() - Device=D8:80:39:F0:03:6E UUID=00002a26-0000-1000-8000-00805f9b34fb
onGetCharacteristic() - Device=D8:80:39:F0:03:6E UUID=00002a28-0000-1000-8000-00805f9b34fb
onGetCharacteristic() - Device=D8:80:39:F0:03:6E UUID=00002a23-0000-1000-8000-00805f9b34fb
onGetCharacteristic() - Device=D8:80:39:F0:03:6E UUID=00002a2a-0000-1000-8000-00805f9b34fb
onGetCharacteristic() - Device=D8:80:39:F0:03:6E UUID=49535343-6daa-4d02-abf6-19569aca69fe
onGetCharacteristic() - Device=D8:80:39:F0:03:6E UUID=49535343-aca3-481c-91ec-d85e28a60318
onGetCharacteristic() - Device=D8:80:39:F0:03:6E UUID=49535343-1e4d-4bd9-ba61-23c647249616
onGetCharacteristic() - Device=D8:80:39:F0:03:6E UUID=49535343-8841-43f4-a8d4-ecbe34729bb3
onGetCharacteristic() - Device=D8:80:39:F0:03:6E UUID=49535343-026e-3a9b-954c-97daef17e26e
onGetDescriptor() - Device=D8:80:39:F0:03:6E UUID=00002902-0000-1000-8000-00805f9b34fb
onGetDescriptor() - Device=D8:80:39:F0:03:6E UUID=00002902-0000-1000-8000-00805f9b34fb
onGetDescriptor() - Device=D8:80:39:F0:03:6E UUID=00002902-0000-1000-8000-00805f9b34fb
onSearchComplete() = Device=D8:80:39:F0:03:6E Status=0
所以我认为我的设备有3个服务和16个特征(每个服务有不同的特征),问题是当我必须发送一个字符时,我使用这个代码
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("00001800-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("00002a04-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");
}
}
所以问题是,必须使用什么服务和特性?我使用我发现的东西。我想向BLE设备发送一个简单的字符,并从UART类型接口接收。我认为您应该使用该服务: 49535343-fe7d-4ae5-8fa9-9fafd205e455 用于数据交换的,具有以下特征: 49535343-8841-43f4-a8d4-ecbe34729bb3
用于写入数据的我认为您应该使用该服务: 49535343-fe7d-4ae5-8fa9-9fafd205e455 用于数据交换的,具有以下特征: 49535343-8841-43f4-a8d4-ecbe34729bb3
用于写入数据的与您通话的设备的规范应指定要使用的特性和服务。与您通话的设备的规范应指定要使用的特性和服务。