I've got an Android Application that listens for incoming data from a paired HC-06 Bluetooth device. The device is connected to my Arduino board and I can send data through it to devices it is paired to by a simple SoftwareSerial.print("Foobar") method and all works well! The Android device reads all of the incoming bytes and does whatever it is supposed to do with it.
However, when the Bluetooth device isn't paired to anything and still gets data to send via the same method, as far as I know, it would keep the data into its buffer? Does a buffer actually exist? Because, when it gets paired to the Android device after calling the method multiple times while the device wasn't paired, the Android device would receive multiple instances of bytes upon pairing. Eg. "FoobarFoobarFoobarFoobar", if I called the method 4 times while the Bluetooth device was not paired to anything.
So far I've learned that the only way to "clear the buffer" would be to read all of the data from it, but it is quite a challenge and gamble to think of a solution especially since all bytes do not arrive instantaneously to the Android device. I still need only one instance of bytes per sending. Using the flush() method isn't what I was expecting it to do.
How to get rid of the unreceived bytes in HC-06's so called 'buffer'?
Your post title doesn't make sense. There is no need to get rid of something you didn't get.
However, when the Bluetooth device isn't paired to anything and still gets data to send via the same method, as far as I know, it would keep the data into its buffer?
Is that a question? I don't see any collection of words there that asks anything.
If it is a statement, it has the wrong punctuation.
Why wouldn't ask the device if it is paired before asking it to send data?
Using the flush() method isn't what I was expecting it to do.
What did you expect it to do? What do you think it actually did? To what buffer?
Well, none of you are even trying to help either. You were ignoring most of the contents of my post. I've summarized my actual issue and current knowledge. That there does not correct/inform or contribute to my question at all. No worries. I'm not in the right community.
No, your not. In this community, when you post a programming question, you are supposed to post your code, too. You are clearly not informed enough about the process of sending and receiving serial data to even be able to ask questions about it. Yet, you are making assumptions about the process using buffers that you want to empty. When we point out that the bluetooth device doesn't have a separate buffer, you get all defensive.
0z_R3n:
Well, none of you are even trying to help either. You were ignoring most of the contents of my post.
If your Arduino sends data using Bluetooth when nothing is listening the data that was sent just vanishes.
The problem you are experiencing is that the Arduino is working and the Android device is listening but is not yet ready to deal with the data. Your Android program should have some means to discard unwanted initial data.
Imagine you walk into a room where someone is talking and you hear the tail end of a sentence. If it matters you will say to the speaker "sorry, I missed the start of that, would you mind repeating it please?". Your Android program needs equivalent logic.
Alternatively, you might choose to ignore the part of the sentence you heard and just listen to the rest of the speech.
I've got an Android Application that listens for incoming data from a paired HC-06 Bluetooth device.
and what does it do with the information it receives ? And how can you filter on the receiving end.
as far as I know, it would keep the data into its buffer? Does a buffer actually exist?
But why are you sending it data while it is not paired ? the BT device probably does have some kind of input buffer since it also responds to commands and needs to store those before interpreting. There probably is some output buffer as well, and maybe there is a way to clear it before sending any data, but it should do so after pairing automatically imo (though i didn't built the thing) check the manual of the HC-05
Oh yeah keep in mind that what seems obvious to you and clearly explained may not be so clear to others.
0z_R3n:
Well, none of you are even trying to help either. You were ignoring most of the contents of my post.
You have been helped as much as you can reasonably expect - here, or anywhere else. Most of the contents of your post is incoherent nonsense, based on false assumptions - including the meaning of "paired".