I'm sending data using and ESP32 and prefix mode AsyncStreams and the B4Rserializer to a B4A app. It's several KB worth of log data.
It's working but only if the bytes sent and received are under 250 bytes give or take. Is there a reason for this? There isn't any MaxBufferSize in B4A as there is in B4R. Is the buffer limited to 256 bytes? Somewhere on the forum I've read that there is no size limit but my experience seems to indicate otherwise. I'd like to sen at least a few KB at a time although 200B at a time does the trick.
Has anybody else done this? Any ideas?
B4R code looks like this. Stack and MaxBufferSize is plenty large. bsize is how much to send at a time.
On the B4A app code looks like this. It receives and stores a chunk with each message and stores it to a file when it knows it has received it all.
It's working but only if the bytes sent and received are under 250 bytes give or take. Is there a reason for this? There isn't any MaxBufferSize in B4A as there is in B4R. Is the buffer limited to 256 bytes? Somewhere on the forum I've read that there is no size limit but my experience seems to indicate otherwise. I'd like to sen at least a few KB at a time although 200B at a time does the trick.
Has anybody else done this? Any ideas?
B4R code looks like this. Stack and MaxBufferSize is plenty large. bsize is how much to send at a time.
B4X:
Private Sub snd_log
Private bsize As UInt = 200
Private fs As ESP8266FileSystem
fs.Initialize
If fs.Exists("/logs.txt") Then
fs.OpenRead("/logs.txt")
Private fl As File
fl=fs.CurrentFile
Private b(bsize) As Byte
Private ret As UInt
For i = 0 To fl.Size Step bsize
ret=fs.Stream.ReadBytes(b,0,bsize)
astream2.Write(ser.ConvertArrayToBytes(Array As Object("logs",fl.Size,ret,b)))
Next
fs.Close
End If
End Sub
On the B4A app code looks like this. It receives and stores a chunk with each message and stores it to a file when it knows it has received it all.
B4X:
Sub astream_NewData (Buffer() As Byte)
Private data() = ser.ConvertBytesToArray(Buffer) As Object
Select data(0)
Case "logs"
If data.Length=4 Then
Private b() As Byte = data(3)
logbuff.Append(BytesToString(b,0,b.Length-1,"utf-8"))
If logbuff.Length >= data(1) Then
File.WriteString(File.DirRootExternal, "log.txt",logbuff.ToString)
logbuff.Remove(0,logbuff.Length-1)
End If
End If
End Select
End Sub