Android Bluetooth LE - BluetoothGatt - onNotify stops receiving data -
Android Bluetooth LE - BluetoothGatt - onNotify stops receiving data -
i connecting bluetooth le peripheral central. writing info characteristic , receive info through notifications in chunks of 20 bytes.
notification subscription:
private void setcharacteristicnotification(bluetoothgattcharacteristic characteristic, boolean enabled) { if (mbluetoothadapter == null || mbluetoothgatt == null) { log.w("bluetoothadapter not initialized"); return; } log.d("enabling notifications"); mbluetoothgatt.setcharacteristicnotification(characteristic, enabled); bluetoothgattdescriptor descriptor = characteristic.getdescriptor(uuid.fromstring(client_characteristic_config)); descriptor.setvalue(bluetoothgattdescriptor.enable_notification_value); mbluetoothgatt.writedescriptor(descriptor); }
this works fine if little number of chunks need received between writes. bluetooth stack sends notifications each chunk:
d/bluetoothgatt﹕ onnotify() - device=b0:ec:8f:00:07:aa uuid=06d1e5e7-79ad-4a71-8faa-373789f7d93c
but if number of chunks between writes bigger 10, stack stops notifications , rest of info lost! device sending more data, can receive on ios devices.
the number of received notifications varies between android devices. galaxy s3 (4.3) receives 5, nexus 5 (4.4.4) , htc 1 (4.4.2) receive 12.
the bt stack closes connection 30 seconds after lastly notification.
d/bluetoothgatt﹕ onclientconnectionstate() - status=0 clientif=5 device=b0:ec:8f:00:00:88
can reproduce issue?
as bluetooth le stack polling based, guess stack stops polling info peripheral reason. target device not back upwards indications.
update: additional info provided android l bluetooths stack:
06-27 12:20:02.982 18909-18946/? d/btgatt.gattservice﹕ onnotify() - address=b0:ec:8f:00:01:09, charuuid=06d1e5e7-79ad-4a71-8faa-373789f7d93c, length=20
06-27 12:20:07.666 18909-18984/? e/btld﹕ ###################################################################### 06-27 12:20:07.666 18909-18984/? e/btld﹕ # 06-27 12:20:07.666 18909-18984/? e/btld﹕ # warning : btu hci(id=0) command timeout. opcode=0xfd55 06-27 12:20:07.666 18909-18984/? e/btld﹕ # 06-27 12:20:07.666 18909-18984/? e/btld﹕ ###################################################################### 06-27 12:20:07.670 18909-18984/? e/bt-btm﹕ can not interpret irk vsc cmpl callback 06-27 12:20:07.670 18909-18984/? w/bt-hci﹕ hci cmd timeout counter 1 06-27 12:20:34.315 18909-18984/? e/bt-btm﹕ btm_sec_disconnected - clearing pending flag
maybe not ideal solution, i've come take notifications not working @ or stopping working unfortunate reality of doing ble on android. in mind, believe it's best if set own "pseudo-notification" backup mechanism doing read poll when appears normal notifications broken. example, in handler#postdelayed()
loop 1 time second. can abstract away behind separate class stores lastly read value , notifies ui when lastly read value doesn't equal new value.
android bluetooth bluetooth-lowenergy android-bluetooth
Comments
Post a Comment