У меня есть малину со следующими характерными (с помощью 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");
}
}
});
Вот мой Log:
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.
Спасибо.