B4R Question Bluetooth Connection - Limited data connection

rodmcm

Active Member
Licensed User
I am porting a B4A APP from AP WIFI to Bluetooth on an ESP32, using the same configuration of astream and B4RSerialization used in the WIFI app

I am sending a 70 x 5 integer array by sending individual astream.writes of 5 converted integers.

This works flawlessly in WIFI but in Bluetooth I only ever receive 18 to 20 transmissions

Sub BT_astream_NewData (Buffer() As Byte)
Log(Count)
Count=Count+1
end sub


No alarms or unusual messages received. I can resent immediately, but again only 18 to 20 transmissions seen

Would anyone have any idea why this limitation is showing up?
 

Erel

Administrator
Staff member
Licensed User
Never hold the main thread in a loop:
B4X:
Sub Wait(ms As Int)
   Dim n As Long = DateTime.Now + ms
   Do While DateTime.Now < n
   Loop
End Sub
Nothing good will come out of this.

Try to add a proper delay:
B4X:
Sub SendProfile
   Log("SendProfile")
   LoadProfileArray                                           'Put some info in for test
   If Starter.BTConnectionState=True Then
       For i=0 To Starter.TotalDays-1
           For j = 0 To Starter.TotalSteps-1
               Starter.SendArray(0) = 2                   'Key for this data
               Starter.SendArray(1) = i                   'DayCount
               Starter.SendArray(2) = Starter.Profile(i,j).data1   
               Starter.SendArray(3) = Starter.Profile(i,j).data2   
               Starter.SendArray(4) = Starter.Profile(i,j).data3
               Log("i= "&i&"  j="&j)
               CallSub(Starter,"SendToESP32")
               Sleep(100) '<------------------------
           Next
       Next   
   Else
       MsgboxAsync("BT not Connected","Cannot Send")
   End If
End Sub
 

rodmcm

Active Member
Licensed User
Thanks Got it from here https://www.b4x.com/android/forum/t...ke-wait-or-delay-for-some-milliseconds.38465/

Also noted that if I enable

Dim be(20) As Object 'used as a storage buffer. Can be a global variable
Dim Data() As Object = ser.ConvertBytesToArray(Buffer,be)
Log("From IPAD ",Data(0)," ", Data(1), " ",Data(2)," ",Data(3)," ",Data(4))


Get the following error after about 20 transmits

Out of bounds error. Array length = 20, Index = 65535
 

rodmcm

Active Member
Licensed User
The sample I posted was a cut down version of a larger program using Bluetooth and I2C.
I removed the I2C portion for test purposes and lo and behold it all came right.
The more I use ESp32 the less I like it. Okay for one or two options but stretch it and it fails

Thanks for assistance
 
Top