Hi
I am transmitting integers from ESp32 to B4A ( only 6 at a time in an array). Having all sorts of problems with errors including B4r Serialization. This experiment went back to basics to try and sort the problem by developing bytes from Ints ( been through the byte converter route as well)
The attached is a summary of the reception at the B4A on a Levono Tablet. Some of the data is fine, then it all turns to custard.
Has anyone any idea why this should be? I have tried different ESP's but unfortunately only one tablet.
Code sending from B4R
Code Receiving at B4A
I am transmitting integers from ESp32 to B4A ( only 6 at a time in an array). Having all sorts of problems with errors including B4r Serialization. This experiment went back to basics to try and sort the problem by developing bytes from Ints ( been through the byte converter route as well)
The attached is a summary of the reception at the B4A on a Levono Tablet. Some of the data is fine, then it all turns to custard.
Has anyone any idea why this should be? I have tried different ESP's but unfortunately only one tablet.
Code sending from B4R
B4X:
Sub SendBT
If btConnected Then
' bt_astream.Write(ser.ConvertArrayToBytes(Array(SendArray(0),SendArray(1),SendArray(2),SendArray(3),SendArray(4),SendArray(5),SendArray(6))))
Log(SendArray(0)," ",SendArray(1)," ",SendArray(2)," ",SendArray(3)," ",SendArray(4)," ",SendArray(5)," ",SendArray(6))
Dim SendByteArray(20) As Byte
Dim j =0 As Int
For i = 0 To 9
SendByteArray(j) =Bit.And(SendArray(i),0xFF)
SendByteArray(j+1) = Bit.And(Bit.ShiftRight(SendArray(i),8),0xff)
j=j+2
Next
Log(SendByteArray(0)," ",SendByteArray(1)," ",SendByteArray(2)," ",SendByteArray(3)," ",SendByteArray(4)," ",SendByteArray(5)," ",SendByteArray(6)," ",SendByteArray(7)," ",SendByteArray(8)," ",SendByteArray(9)," ",SendByteArray(10)," ",SendByteArray(11)," ",SendByteArray(12)," ",SendByteArray(13))
bt_astream.Write(SendByteArray)
Delay(400)
End If
End Sub
Code Receiving at B4A
B4X:
AStream_NewData (Buffer() As Byte)
'Log("Buffer Length "& Buffer.length)
'Log(bc.HexFromBytes(Buffer))
If Buffer.Length Mod 2 = 0 And Buffer.Length<=20 Then
Log(Buffer(0) &" "&Buffer(1) &" "&Buffer(2) &" "&Buffer(3) &" "&Buffer(4) &" "&Buffer(5) &" "&Buffer(6) &" "&Buffer(7) &" "&Buffer(8) &" "&Buffer(9) &" "&Buffer(10) &" "&Buffer(11) &" "&Buffer(12) &" "&Buffer(13) &" "&Buffer(14) &" "&Buffer(15) &" "&Buffer(16) &" "&Buffer(17) &" "&Buffer(18) &" "&Buffer(19))
Dim Data(Buffer.length) As Int
Dim j As Int =0
For i=0 To Buffer.Length-1 Step 2
Dim Byte1 As Byte =Bit.Shiftleft(Buffer(i+1),8)
'Data(j) = Bit.Or(Buffer(i),Bit.Shiftleft(Buffer(i+1),8)) ' Adds bytes to make an integer
Data(j) = Bit.Or(Buffer(i),Byte1)
j=j+1
Next
If Data.Length = 0 Then Return 'invalid message
Log("FromESP32 "& Data(0) & " "& Data(1) &" " & Data(2) & " " & Data(3)&" "& Data(4)&" "& Data(5)&" "& Data(6))