【问题标题】:Reading a Bluetooth LE array from UUID?从 UUID 读取蓝牙 LE 阵列?
【发布时间】:2016-06-07 20:39:52
【问题描述】:

我正在尝试从蓝牙 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();
        }

【问题讨论】:

    标签: android arrays android-studio bluetooth bluetooth-lowenergy


    【解决方案1】:

    在数组末尾添加带有我想要的字节的括号给了我想要的数据。

    Log.d(TAG, "characteristic read: "+characteristic.getValue()[4]); 会给我第四个字节。

    【讨论】:

      猜你喜欢
      • 2017-02-10
      • 1970-01-01
      • 2013-12-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-26
      • 2013-10-25
      • 1970-01-01
      相关资源
      最近更新 更多