How do I get the write response in an android application of a write to a characteristic which has write response?
I can't find any callback for this. Only way I can think of is if onCharacteristicWrite status returns failed when the response is not received, difficult to confirm if it works like this though.
Note: I don't mean for Write Without Response, but the 4.9.3 Write Characteristic Value in Bluetooth Core Specification 5.0.
When onCharacteristicWrite is called with success status and the write type was Write With Response, that means you got the write response ;)
If no write response is received within 30 seconds the link gets disconnected.
Related
i'm developping an android app that communicate with a BLE device(in kotlin).
i'm sending a command to the ble device, the device usually give the following response:
-OK(confirming the command was received and valid)
-one or multiple line of data
-Done
in onCharacteristicWrite i tryed to show this.value to read the response but look like it's not the way to do it. i googled a lot without lot of success.
so my question is how could i get the data from the response.the device send?
i try to call a readCharateristic without success either.
thank you for your help
GATT does not have any protocol feature of a request - response transaction where both messages embed data.
For Write Request - Write Response, only the request can contain data. The response can only be empty or an error code.
For Read Request - Read Response, the request contain only what characteristic is to be read and the response contains some data or an error code.
To implement a request - response mechanism using GATT, one usually follows one of the following strategies:
Use Write Request or Write Without Response for the request message and Notification for the response message.
Use Write Request or Write Without Response for the request message. When the GATT server produces a response message, it is put in a characteristic that the client will then read using a Read Request.
The first method has lowest overhead and best throughput.
What you should do is to investigate what method your peripheral actually uses. If it sends its responses in notifications, you must enable these and implement the onCharacteristicChanged callback.
I am invoking the writeCharacteristic both using the WRITE_TYPE_NO_RESPONSE and without it.Am I supposed to get the response out of both or one or none?
Is there any callback to catch this response?
Does onReliableWriteCompleted callBack ensures the successful delivery of the Message at the BLE device side(from the Phone) or does it implies that the message has been sent to the device(From the Phone) successfully and has been released in air.
If you use the WRITE_TYPE_NO_RESPONSE, you will get the onCharacteristicWrite callback as soon as the stack is ready and has space to accept a new request. This does not mean the other side has received it.
If you don't use WRITE_TYPE_NO_RESPONSE, you will get the onCharacteristicWrite callback as soon as the remote device has sent back a Write Response.
The onReliableWriteCompleted will be called when the remote side has acknowledged everything.
I'm working on an android BLE app. I have a BLE device which storing the coordinates of where the device went.
In order to get the data from the device after connected, we will need to send several commands and read its response. The steps are as follow:
Send first command to device
Read response (some data..)
Send second command to device
Read response (coordinates)
And this is how I did
After connected, sending a command to the device by using writeCharacteristic
When receiving GATT_SUCCESS in onCharacteristicWrite callback, call readCharacteristic to read its response
When receiving GATT_SUCCESS in onCharacteristicRead callback, continue to send second command to the device by using writeCharacteristic
When receiving GATT_SUCCESS in onCharacteristicWrite callback, call readCharacteristic to read its response
So here's the problem, when I issued readCharacteristic after write operation succeeded, the response is not expected as always and sometime it return the same command that I wrote. However, if I put some delay (e.g. 1 second) after I write, the response is correct when I read but the delay may different every time.
I am wondering if anyone having the same issue like this or anyone can explain to me why is this happening? Is that possible that we can know when is the correct time to read the characteristic?
Note: The device does not provide any notification/indication.
Is there someone using blob request (long read) from an android device?
We work with a CC2540 from TI, connected to a android 4.4.
We try to read a long characteristic value (size more than 23 bytes). In the android API for BLE, we have not seen a readBlob or readLong method.
We expect that the Android BLE Stack do the job for us, by reading a characteristic presentation format (same way has notification), but it doesn't works.
We have no idea how to send Blob Request through Android.
Let me make this clear that Android has only one method to read the value of a characteristic, readCharacteristic(characteristic). You can use this method to get the value of a characteristic of any length. Android takes care of forming a ReadBlob request; it's all in the back end. You'd have to change the code of your CC2540 though, to make it work with ReadBlob request. Once you make all the required changes at your CC2540 end, on calling readCharacteristic() from Android, you'll get the entire value of the characteristic which you can access in the onCharacteristicRead() callback.
You canĀ“t, BLE characteristic values are limited at 20 bytes. So if you want to send or receive more than 20 bytes, you have to split it into 20 byte chunks. See this topic on the issue.
I am developing an application that read data from biometric devices using Bluetooth when I send request to biometric device for sending data, biometric device show response with updating its display screen but when I call function for read input stream for getting response the function in_stream.available() return 0. I am not able to trace out the root of problem. I have test same biometric device with some other app it work fine.
Help me if any one have idea about this issue.
Thanks in advance.
Do no use available() method. It is broken in most implementations. You should be constantly reading with read() or read(byte []). If the protocol lets you know the size of the expected data (i.e. some first bytes telling how much data is coming afterwards) you can just read that amount of data.
If the amount of data is unknown or you expect asynchronous data comming then you should manage the writing/reading to/from the streams in a separate thread. This does not only applies to Bluetooth but also to any basic stream handling (network, files, etc.)