首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >我的BLE设备无法从Android接收数据

我的BLE设备无法从Android接收数据
EN

Stack Overflow用户
提问于 2016-09-17 00:10:35
回答 1查看 251关注 0票数 0

我有一个覆盆子,具有以下特性(使用Node.JS和Bleno库):

代码语言:javascript
复制
PrinterCharacteristic.prototype.onWriteRequest = function(data, offset, withoutResponse, callback) {
    this._value = data

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

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

下面是我的Android代码:

代码语言:javascript
复制
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");
        }
    }

});

这是我的日志:

代码语言:javascript
复制
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()

它发现了两个特征(正如预期的那样,写入和通知),并尝试向每个特征发送数据,但我的raspberry没有接收到任何数据。

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

我做错了什么?我不确定我确切地理解了BLE是如何工作的。

谢谢。

EN

回答 1

Stack Overflow用户

发布于 2016-09-17 00:32:24

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39535931

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档