Android Question Trying to understand BLE WriteWithoutResponse/Write property

jimseng

Active Member
Licensed User
Longtime User
Hello. I have managed to get a BLE app sending bytes to a Pi Pico but I don't understand the difference between the two properties, or that is to say, whether one can choose which one to use. The characteristic returns both properties but there doesn't seem to be any way of choosing which one to "use". I can't find an explanation as to what these two properties relate to. I wonder if I have missed a whole thread that explains this in detail.
 

walterf25

Expert
Licensed User
Longtime User
Hello. I have managed to get a BLE app sending bytes to a Pi Pico but I don't understand the difference between the two properties, or that is to say, whether one can choose which one to use. The characteristic returns both properties but there doesn't seem to be any way of choosing which one to "use". I can't find an explanation as to what these two properties relate to. I wonder if I have missed a whole thread that explains this in detail.
Normally when you communicate with a BLE device, you need to know the characteristics of the device you are talking to, with that said, you will notice that there are certain characteristics that are Write/Read/Notify characteristics. What this means is that you should be able to Write data and read data back from said characteristic. On the Notify Option the _DataAvailable function will be raised anytime there's new data available if you set the characteristic to notify you whenever there's new data available.

There are characteristics that are Write only, meaning you will not get a response, I believe that's what the WriteWithoutResponse command is in this case, you should only use this command if you know that there should not be a response from the device you are talking to at a specific characteristic.

Hope this helps.
Walter
 
Upvote 0

jimseng

Active Member
Licensed User
Longtime User
Hi.
if you set the characteristic to notify you whenever there's new data
I think this is the bit where I am getting confused. As far as I can tell there are two properties for the characteristic, write and WriteWithoutResponse. The method available is manager.WriteData("serviceID","characteristic",byte), I can't see how/if I can "set" which property to use, Write or WriteWithoutResponse. I haven't found a tutorial that explains this clearly enough.
A _WriteComplete event is raised when I send the data but I can't figure out if this is returned by the BLE peripheral or whether it is the B4X app side. I am trying to figure out how to send data and not care if it arrives or not. Currently if I go out of BLE range my app hangs or crashes when I WriteData. I can handle that just so long as I know if I have to, or whether there is a different approach.
 
Upvote 0

walterf25

Expert
Licensed User
Longtime User
Hi.

I think this is the bit where I am getting confused. As far as I can tell there are two properties for the characteristic, write and WriteWithoutResponse. The method available is manager.WriteData("serviceID","characteristic",byte), I can't see how/if I can "set" which property to use, Write or WriteWithoutResponse. I haven't found a tutorial that explains this clearly enough.
A _WriteComplete event is raised when I send the data but I can't figure out if this is returned by the BLE peripheral or whether it is the B4X app side. I am trying to figure out how to send data and not care if it arrives or not. Currently if I go out of BLE range my app hangs or crashes when I WriteData. I can handle that just so long as I know if I have to, or whether there is a different approach.
I see what you mean, yeah there's no method in the library that would allow you to set the setWriteType of the characteristic, But in reality do you really need it? if you are not expecting a response then why even bother checking?

Walter
 
Upvote 0

jimseng

Active Member
Licensed User
Longtime User
Thanks for the response. It's really more about trying to understand the whole thing. This is my first go at BLE, I have done classic Bleutooth with android but this is new to me and I have struggled to find any tutorials that really explain the whole thing. And I was wondering if the hang/crash when going out of range was to do with it or a completely separate issue that needs handling a different way.
 
Upvote 0

walterf25

Expert
Licensed User
Longtime User
Thanks for the response. It's really more about trying to understand the whole thing. This is my first go at BLE, I have done classic Bleutooth with android but this is new to me and I have struggled to find any tutorials that really explain the whole thing. And I was wondering if the hang/crash when going out of range was to do with it or a completely separate issue that needs handling a different way.
When you say hang/crash when going out of range, what does that mean exactly, what values are you going out of range?

Walter
 
Upvote 0

jimseng

Active Member
Licensed User
Longtime User
I am sending two bytes from a panel touch event, the first byte identifies the panel and the second the y value of the touch event. It is sort of creating a vertical seek bar to control pwm values on the peripheral. If I try to send these two bytes after walking far enough away the app hangs, I assume because the Bluetooth signal is out of range. I haven't tried to debug it yet and it isn't really the point of my original question. I haven't yet paid attention to whether the app recognizes a disconnection. I really want to try to understand BLE as much as I can because I love to learn. I think my whole post is about whether Write and WriteWithoutResponse are two distinct methods available in B4X.
 
Upvote 0

f0raster0

Well-Known Member
Licensed User
Longtime User
Maybe this can help:

"Write
If the client wishes to write a certain value to an attribute, it sends a write request and provides data that matches the same format of the target attribute. If the server accepts the write operation, it responds with an acknowledgement.

Write without response
If this operation is enabled, a client can write data to an attribute without waiting for an acknowledgment from the server. This is a non-acknowledged write operation that can be used when quick data exchange is needed"

From:
 
Upvote 0
Top