2016-09-16 67 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應使用哪一個特徵。