我的 BLE android 应用程序当前可以连接到我的 BLE 硬件并连接到 GATT 服务器。我还可以启用通知并读取特征。然而,所宣传的特征是 HEX 格式。在我的服务上,我尝试接收字符串或字节数组格式的数据,尝试了几个转换过程,但我仍然得到无意义的数据(即??x 等)
关于如何接收/转换十六进制数据的任何想法?服务:
private void broadcastUpdate(final String action,
final BluetoothGattCharacteristic characteristic) {
final Intent intent = new Intent(action);
if (UUID_BLE_SHIELD_RX.equals(characteristic.getUuid())) {
//final byte[] rx = characteristic.getValue();
final String rx=characteristic.getStringValue(0);
//final char rx=raw(char.value)
intent.putExtra(EXTRA_DATA, rx);
}
主要活动:
private final BroadcastReceiver mGattUpdateReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
final String action = intent.getAction();
if (Service.ACTION_GATT_DISCONNECTED.equals(action)) {
} else if (Service.ACTION_GATT_SERVICES_DISCOVERED
.equals(action)) {
getGattService(mBluetoothLeService.getSupportedGattService());
} else if (Service.ACTION_DATA_AVAILABLE.equals(action)) {
displayData(intent.getExtras().getString(Service.EXTRA_DATA));
}
NRF 连接中看到的来自 BLE 模块的数据:(0x)04-01-19-00-BE