0

I modified the Android Bluetooth chat example a bit and notice strange delays in the arrival of messages. My setup:

  • One side (A) sends 10 messages per second.
  • The other side (B) then receives the messages an measures the time difference between them.

They arrive at regular intervals: For each sample of 100 messages, the largest measured time difference is always below 150 ms. So far, so good.

Now B also sends a single message. On some devices, after a few seconds, some messages from A will be received by B with a large delay. There will be nothing for 500-1000 ms, then the delayed messages will arrive quickly behind each other. Out of 100 messages, there will be 3-6 such delays.

Now if B also sends messages every now and then (once per second), this problem does not occur. Also, it will not happen if B never sends a message. I tested a number of tablets, and not all show this problem. I notice it with Samsung and Huawei tablets with Android 8 or 9, but I think it does not happen with Nexus 7 or Sony tablets with Android 5 and 6.

It looks to me a bit like the Bluetooth driver will go to sleep every now and then, but only once the device has sent a message. Did anyone else notice this behavior, and did you find a better solution to avoid those delays?

(My app is the Android Bluetooth chat example, just modified to continuously send messages at a certain interval at the push of a button.)

  • Is device A connected to device B and writing on a characteristic or is device A advertizing the chat data to device B ? – matdev Jan 30 '20 at 14:14
  • They are connected and use RFCOMM. – Freilauf Jan 30 '20 at 16:39
  • So your device B act both as BLE peripheral and center i.e. advertizing and listening ? Bare in mind that there as some limitation: applications are prevented from starting and stopping scans more than 5 times in 30 seconds – matdev Jan 31 '20 at 10:28
  • Ah, no, this is not Bluetooth LE. But I now found this related question: https://stackoverflow.com/questions/27229813/real-time-bluetooth-spp-data-streaming-on-android-only-works-for-5-seconds Not sure why I did not see this before. – Freilauf Jan 31 '20 at 16:46

0 Answers0