【问题标题】:My BLE device does not receive data from Android我的 BLE 设备没有从 Android 接收数据
【发布时间】:2016-09-16 16:10:35
【问题描述】:

我有一个具有以下特征的树莓(使用 Node.JS 和 Bleno 库):

PrinterCharacteristic.prototype.onWriteRequest = function(data, offset, withoutResponse, callback) {
    this._value = data

    console.log('onWriteRequest working with "'+ this._value + '"')
}

另外,我的 Android 设备应该与该设备绑定并向其发送数据。

这是我的 Android 代码:

BluetoothGatt mBluetoothGatt = device.connectGatt(getActivity(), false, new BluetoothGattCallback() {

    @Override
    public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
        super.onConnectionStateChange(gatt, status, newState);

        if (status == BluetoothGatt.GATT_SUCCESS) {
            Log.d("BLE", "start discover");
            gatt.discoverServices();
        }
    }

    @Override
    public void onServicesDiscovered(BluetoothGatt gatt, int status) {
        Log.d("BLE", "onServicesDiscovered");

        if (status == BluetoothGatt.GATT_SUCCESS) {
            BluetoothGattService mService = gatt.getServices().get(0);
            for (BluetoothGattCharacteristic bgc : mService.getCharacteristics()) {
                Log.d("BLE", "characteristic " + bgc.getUuid() + " " + bgc.toString());

                bgc.setValue("Hello World");

                Log.d("BLE", "writing characteristc");
                gatt.writeCharacteristic(bgc);
            }

        } else {
            Log.d("BLE", "onServicesDiscovered error");
        }
    }

});

这是我的日志:

09-16 13:03:46.769 18585-18585/us.inevent.apps.whiteLabel D/BluetoothGatt: connect() - device: B8:27:EB:98:BE:9D, auto: false
09-16 13:03:46.769 18585-18585/us.inevent.apps.whiteLabel D/BluetoothGatt: registerApp()
09-16 13:03:46.770 18585-18585/us.inevent.apps.whiteLabel D/BluetoothGatt: registerApp() - UUID=9a602983-99db-45fd-a3a3-2eb3ed72989a
09-16 13:03:46.772 18585-18987/us.inevent.apps.whiteLabel D/BluetoothGatt: onClientRegistered() - status=0 clientIf=6
09-16 13:03:47.192 18585-18602/us.inevent.apps.whiteLabel D/BluetoothGatt: onClientConnectionState() - status=0 clientIf=6 device=B8:27:EB:98:BE:9D
09-16 13:03:47.193 18585-18602/us.inevent.apps.whiteLabel D/BLE: start discover
09-16 13:03:47.193 18585-18602/us.inevent.apps.whiteLabel D/BluetoothGatt: discoverServices() - device: B8:27:EB:98:BE:9D
09-16 13:03:47.249 18585-18601/us.inevent.apps.whiteLabel D/BluetoothGatt: onSearchComplete() = Device=B8:27:EB:98:BE:9D Status=0
09-16 13:03:47.249 18585-18601/us.inevent.apps.whiteLabel D/BLE: onServicesDiscovered
09-16 13:03:47.250 18585-18601/us.inevent.apps.whiteLabel D/BLE: characteristic 00002a00-0000-1000-8000-00805f9b34fb android.bluetooth.BluetoothGattCharacteristic@1b258afb
09-16 13:03:47.250 18585-18601/us.inevent.apps.whiteLabel D/BLE: writing characteristc
09-16 13:03:47.250 18585-18601/us.inevent.apps.whiteLabel D/BLE: characteristic 00002a01-0000-1000-8000-00805f9b34fb android.bluetooth.BluetoothGattCharacteristic@3876d718
09-16 13:03:47.250 18585-18601/us.inevent.apps.whiteLabel D/BLE: writing characteristc
09-16 13:03:47.533 18585-18585/us.inevent.apps.whiteLabel D/BluetoothAdapter: stopLeScan()

它发现了两个特征(如预期的那样,WRITE 和 NOTIFY),并尝试向它们中的每一个发送数据,但我的树莓派没有收到任何数据。

如果我使用nRF Connect 应用程序,它会按预期工作。

我做错了什么?我不确定我是否完全理解 BLE 的工作原理。

谢谢。

【问题讨论】:

    标签: android node.js bluetooth-lowenergy


    【解决方案1】:

    Bleno 似乎有另一个服务正在运行。为了解决我的问题,我刚刚搜索了所有服务中的所有特征,并确定了 UUID 应该使用哪一个。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-05-25
      • 2021-07-15
      • 1970-01-01
      • 2023-04-03
      • 2013-11-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多