B4R Question Joining arrays of bytes in B4R on ESP8266

JMB

Active Member
Licensed User
Longtime User
Hi.

I have been playing around with the Tutorial code used to set up the Wifi through the Access point on an ESP8266.

I want to be able to send a series of objects as one group from the ESP to a controlling device.

I am using the stored values in the EEPROM as per Erel's code to send back the data, but I am trying to send back a Command string before that data.

The code currently looks like this:

B4X:
Dim StoredLength As Byte = GetStoredDataLength
Dim Command() As Byte = serializator.ConvertArrayToBytes(Array("ESP Settings"))
Dim EEPROMSettings() As Byte = eeprom.ReadBytes(2, StoredLength)

The EEPROM settings data has seven objects stored in there as per the code in Erel's AP access code.

If I send this data using
B4X:
JBAsyncStream.Write(Command).Write(EEPROMSettings)

I end up getting one object received (the Command), then a separate set of 7 objects. But it requires two Async_NewData calls at the receiver to do this.

How can I combine the Command bytes with the EEPROM settings so that instead of two calls being made, I just have one call with 8 objects being transmitted?

I tried using

B4X:
Dim FinalOuput() As Byte = JoinBytes(Array(Command,EEPROMSettings))
JBAsyncStream.Write(FinalOuput)

But that only seemed to send the Command bit.

Thanks for any help,

JMB
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
But that only seemed to send the Command bit.
It sends everything. However it sends it as two separate serialized packages one after another.

It will be simpler to send them separately (without JoinBytes) and use Wait For to wait for the second message:
B4X:
Sub AStream_New(Data() As Byte)
 'deserialize the message with B4RSerializator
 If message = "ESP Settings" Then
  Wait For (astream) AStream_NewData(Data() As Byte)
   'get the second part
 End If
End Sub

I assume that you are using AsyncStreams in prefix mode.
 
Upvote 0
Top