Android BLE Gatt Characteristic WRITE_TYPE_NO_RESPONSE not working

陌路散爱 提交于 2020-01-03 09:54:49

问题


I have developed an Android app that connects to a CC2540 BLE peripheral.

When I do a Characteristic write of type no response (WRITE_TYPE_NO_RESPONSE), I still get the callback onCharacteristicWrite at the app level. Is this behavior correct?

I understand there is probably a low level acknowledgement that occurs between the Android device and the peripheral.

But the reason I am asking is because this is causing an issue where I can only send a write once I have received this callback, which is slowing things down in the app.

Any light on this behavior would be appreciated it.

Thanks,


回答1:


I did run into the same problem when I was trying to do some performance testing and found that when I used the WRITE_TYPE_DEFAULT specifically I stopped getting a response. There might be a bug with the android constants that is causing inverse behavior, but I am not quite not sure.




回答2:


you can only make 1 transfer at a time on the low level so you need a callback to tell when the stack is ready to send another command. If you try to send several after each other without waiting for the air-interface to be ready you can seriously crash the BLE stack! This was happening a lot on earlier iOS CoreBluetooth. If one app crashes the BLE Stack then the phone need a reset or Bluetooth must be turned off and on again to reset the stack. The callback just tells you that the stack has send a request over the air-interface, not that it was acknowledged by the recipient. For that you would use the other api which will make the BLE Stack re-transmit several times (depending on how the connection parameters has been negotiated).

It's stated clearly in the BLE specification that only 1 transfer can be made at a time.

If you just bang the API with write requ



来源:https://stackoverflow.com/questions/21791948/android-ble-gatt-characteristic-write-type-no-response-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!