从 UUID 读取蓝牙 LE 阵列?
Reading a Bluetooth LE array from UUID?
我正在尝试从蓝牙 LE 设备发送给我的数组中读取数据。
数据流应为 18 个字节,当作为数组查看时,我需要字节 5、6 和 7。
我有 service
和 characteristic
的正确 UUID。但是,我不知道如何从 characteristic
获取数组。
现在我只是想获取我认识的数据。但是,下面的日志语句产生了我无法理解或无法与数据匹配的随机字符。
此函数中唯一真正重要的行是带有 characteristic.getValue()
的日志,但我想我会包括整个内容以提供一些上下文。
@Override
public void onCharacteristicRead(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) {
Log.d(TAG, "characteristic read: "+characteristic.getValue());
gatt.setCharacteristicNotification(characteristic, true);
gatt.readRemoteRssi();
runOnUiThread(update_UI);
try {
Thread.sleep(500);
} catch(InterruptedException ex) {
Thread.currentThread().interrupt();
}
gatt.discoverServices();
}
在数组末尾添加带有我想要的字节的括号给了我想要的数据。
Log.d(TAG, "characteristic read: "+characteristic.getValue()[4]);
会给我第四个字节。
我正在尝试从蓝牙 LE 设备发送给我的数组中读取数据。
数据流应为 18 个字节,当作为数组查看时,我需要字节 5、6 和 7。
我有 service
和 characteristic
的正确 UUID。但是,我不知道如何从 characteristic
获取数组。
现在我只是想获取我认识的数据。但是,下面的日志语句产生了我无法理解或无法与数据匹配的随机字符。
此函数中唯一真正重要的行是带有 characteristic.getValue()
的日志,但我想我会包括整个内容以提供一些上下文。
@Override
public void onCharacteristicRead(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) {
Log.d(TAG, "characteristic read: "+characteristic.getValue());
gatt.setCharacteristicNotification(characteristic, true);
gatt.readRemoteRssi();
runOnUiThread(update_UI);
try {
Thread.sleep(500);
} catch(InterruptedException ex) {
Thread.currentThread().interrupt();
}
gatt.discoverServices();
}
在数组末尾添加带有我想要的字节的括号给了我想要的数据。
Log.d(TAG, "characteristic read: "+characteristic.getValue()[4]);
会给我第四个字节。