Android Question BLE2. Transfer stops after sending 600 bytes.

red30

Well-Known Member
Licensed User
Longtime User
There are two android devices:
Screenshot_2021-10-28-08-44-54.png
Screenshot_20211027-181356.png
There is also an FSC-BT616 bluetooth module, which is connected to a PC via a UART-USB converter.
Program code:
B4X:
    Public SaveDeviceId As String 
    Public SaveServiceId As String
    Public SaveCharacteristicId As String
    Public ServiceIdStartsWith As String  = "0000fff0"
    Public CharacteristicIdStartsWith_1 As String = "0000fff1"
    Public CharacteristicIdStartsWith_2 As String = "0000fff2"

Sub BleMan_DeviceFound (Name As String, Id As String, AdvertisingData As Map, RSSI As Double)
    Log("DeviceFound = " & Id.Trim & " " & Name.Trim & " " & RSSI)
    If SaveDeviceId = "" Then    'if we haven't yet found the device we're looking for
        If Name="FSC-BT616" Then
            BleMan.StopScan
            Sleep(500)
            SaveDeviceId = Id
            BleMan.Connect2(SaveDeviceId, False)
        End If
    End If
End Sub

Sub BleMan_Connected (Services As List)
    Log("Connected")
    Sleep(500)
    For Each SS As String In Services
        Log("Service = " & SS)
        If SaveServiceId = "" Then    'if we haven't yet found the service we're looking for
            If SS.StartsWIth(ServiceIdStartsWith) Then
                SaveServiceId = SS    'then save it
                BleMan.ReadData(SaveServiceId)    'and read it
            End If
        End If
    Next
End Sub

Sub BleMan_DataAvailable (ServiceId As String, Characteristics As Map)
    For Each C As String In Characteristics.Keys
        Dim V() As Byte = Characteristics.Get(C)
        If SaveCharacteristicId = "" Then
            If ServiceId = SaveServiceId Then
                If C.StartsWith(CharacteristicIdStartsWith_1) Then
                    BleMan.SetIndication(SaveServiceId, C, True)
                else if C.StartsWith(CharacteristicIdStartsWith_2) Then
                    SaveCharacteristicId = C
                End If
            End If
        End If
    Next
End Sub
And then I send an 8-byte packet every 500ms in an endless loop and see it in the terminal on the PC.
B4X:
    For i=0 To 10000
        Sleep(500)
        BleMan.WriteData(SaveServiceId,SaveCharacteristicId,Array As Byte(0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07))
    Next
On a Samsung tablet, this transfer can go on and on. And on the digma tablet, it comes equal to 600 bytes and then, no matter how much I call WriteData, the data is not sent. If I try to reconnect, then again I can only send 600 bytes. As if the digma tablet has some kind of buffer that limits the transfer to > 600 bytes. Is it possible to clean it periodically? Why it happens? Is it possible to somehow solve this problem?
Screen of the service I'm working with:
photo_2021-10-28_09-12-18.jpg
P.S. One might think that the matter is in the tablet, but I tried to use this tablet (digma) with another bluetooth module (HC-08) and there the transfer does not stop after 600 bytes and everything works fine.
 
Last edited:

red30

Well-Known Member
Licensed User
Longtime User
After studying a little more, I realized that it doesn't matter if I transfer data or not, on the digma tablet, the connection is always disconnected after about 1 minute after connecting. Why is this happening? Why doesn't this happen with other HC-08 bluetooth module? And why does this not happen with other tablets when using the FSC-BT616 bluetooth module?
 
Upvote 0

red30

Well-Known Member
Licensed User
Longtime User
Then I tried to use the application from the [B4X] BLE 2 theme:
Digma tablet (Android 6), I connect to the FSC-BT616 module, after "Connected" in the logs it takes exactly 1 minute, and "Disconnected" occurs. If I connect to the HC-08 module with this tablet, the connection is not broken.
Samsung tablet (Android 5.0.2), I connect to the FSC-BT616 module or to the HC-08 module, the connection is not lost once.
HTC phone (Android 9), I connect to the FSC-BT616 module or to the HC-08 module, the connection is not lost once.
I don't understand why this is happening ... Why only in the combination digma + FSC-BT616, after 1 minute the connection is lost. How can this problem be solved?
 
Last edited:
Upvote 0

techknight

Well-Known Member
Licensed User
Longtime User
Yeah, cheap tablets have dismal performance on bluetooth. I have learned this lesson the hard way.
 
Upvote 0

red30

Well-Known Member
Licensed User
Longtime User
Yeah, cheap tablets have dismal performance on bluetooth. I have learned this lesson the hard way.
Yes, I understand that this is a cheap and terrible tablet, but I do not understand why it works fine with one HC-08 bluetooth module, and loses connection with another FSC-BT616 bluetooth module after one minute. I thought it was a software error, I tried to install a new android OS, but the connection is also lost after 1 min. This does not look like a hardware error of the device, but as if it was done on purpose ... The time is too accurate one minute.
 
Upvote 0

Sandman

Expert
Licensed User
Longtime User
Let's assume you're right: it's a software problem somewhere. It can't really be in your code, so it has to be the OS. Now what, how are you going to solve that? No can do.

Bottom line: Don't waste time trying to solve this by understanding why it doesn't work. Solve this by changing the broken parts.
 
Upvote 0
Top