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?
 

rodmcm

Active Member
Licensed User
Erel
Please find enclosed a very stripped down example that shows the problem. I have forced information into a 7 x 10 profile int array and then send this.
 

Attachments

  • BluetoothTest-B4A.zip
    29.7 KB · Views: 297
  • BluetoothTest-B4R.zip
    1.2 KB · Views: 280
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime 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
 
Upvote 0

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
 
Upvote 0

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
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…