B4R Question astream.write2

positrom2

Active Member
Licensed User
Longtime User
I want to test on the maximum size of a message that can be sent by the ESP8266 server.
I used the B$R code from
https://www.b4x.com/android/forum/threads/esp8266-getting-started.68740/
This section does not work (astream.write2....: error: missing parameter)
Code: Copy
Sub Timer1_Tick
Dim ar(3000) As Byte
  If server.Socket.Connected Then
  astream.Write2(ar(),1,1000)' "Time here is: ", Millis)))
  End If
End Sub
How to do it right?
 
It should be like this:
Code: Copy
 astream.Write2(ar, 1, 1000)
But you must set ar to have data in it, after the dim declaration it is empty.
 
Upvote 0
The B4J_connectToEsp8266 reports "Invalid Input" when I try to send the Array by astream1.Write2(ar,1,10) instead of the (commented) Time message.
What's wrong?
Code: Copy
Sub Timer1_Tick
Dim ar(3000) As Byte
For i=0 To 1000
    ar(i)=1
Next
If server.Socket.Connected Then
astream.Write2(ar,1,10)  
'  astream.Write(ser.ConvertArrayToBytes(Array("Time here is: ", Millis)))
End If
End Sub
 
Upvote 0
The B4J_connectToEsp8266 reports "Invalid Input" when I try to send the Array by astream1.Write2(ar,1,10) instead of the (commented) Time message.
What's wrong?
Code: Copy
Sub Timer1_Tick
Dim ar(3000) As Byte
For i=0 To 1000
    ar(i)=1
Next
If server.Socket.Connected Then
astream.Write2(ar,1,10)
'  astream.Write(ser.ConvertArrayToBytes(Array("Time here is: ", Millis)))
End If
End Sub
If you have not changed the b4j "Sub AStream_NewData (Buffer() As Byte)"
then you have a problem by trying to read the output of the serializer, while it was not made by it.
Just check each byte from the received buffer.
 
Upvote 0
Just check each byte from the received buffer.
Instead of using B4J (stopped), I connect a terminal emulator to the ESP8266-01 USB-converter com port.
However with none of the settings in the Board Selector log: (IDE, B4J serial connector, None) I get the output from the astream.write2(ar,1,10) to the terminal emulator.
All what I see is
"Connected to wireless network.
My ip: 192.168.178.20"
I also tried to set up a second asyncstream channel, but that did not work either.
How can I direct astream.write2(ar,1,10) to that com port that also is set in the board selector window?
 
Upvote 0
Hi,

not sure if it helps, but have tested on a Arduino MEGA and WeMOS D1 (ESP8266), below sample code which just uses the serial line.
[EDIT]
1) Checked the serial line output (COM4, COM5) with the B4R IDE, B4R_Serial_Connector, ... each reported AStream Bytes written but the bytes are not displayed.
2) Tested with the Arduino IDE Serial Monitor and the 10 bytes are displayed.

Code: Copy
Sub Process_Globals
    Public Serial1 As Serial
    Private astream As AsyncStreams
    Private timer1 As Timer
End Sub

Private Sub AppStart
    Serial1.Initialize(115200)
    Log("AppStart")
    astream.Initialize(Serial1.Stream, "astream_NewData", "astream_Error")
    timer1.Initialize("timer1_Tick", 3000)
    timer1.Enabled = True
End Sub

Sub Timer1_Tick
    Dim ar(3000) As Byte
    For i=0 To 1000
        ar(i)=1
    Next
    astream.Write2(ar,1,10)
    Log("AStream Bytes written")
End Sub

Sub AStream_NewData (Buffer() As Byte)
   Log("AStream Received:", Buffer)
End Sub

Sub AStream_Error
  Log("AStream Error")
End Sub
 
Last edited:
Upvote 0
rwblinn, thanks you, that code worked, sending ten x01 Bytes.

Now trying to understand Erel's example:
https://www.b4x.com/android/forum/threads/esp8266-getting-started.68740/
Why does it not matter which of the options in the Board selector screen is checked (checking "None" works).
Should'nt it be an example for the B4J serializator?

Now, trying to send output to a terminal emulator by opening a second astream channel:
Code: Copy
Private Sub AppStart
Serial1.Initialize(115200)
astream1.Initialize(Serial1.Stream, "astream_newdata", Null)
Log("AppStart")
....
If server.Socket.Connected Then
astream1.Write2(ar,1,10)   
astream.Write(ser.ConvertArrayToBytes(Array("Time here is: ", Millis)))
End If
I do not get output to a terminal emulator although I can open the com port.
 
Upvote 0
Back
Top