2016-09-16 15 views
0

接收数据我有以下特点(如何使用Node.js和Bleno库)咂舌:我的BLE装置没有从Android的

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 [email protected] 
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 [email protected] 
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的工作原理。

谢谢。

回答

0

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