B4R Question ESP8266 Socket and astream problem

tzfpg

Active Member
Licensed User
Longtime User
I write a small project to test B4R (WiFiSocket client) send byte array to B4J (ServerSocket Server). Server side can received the byte array but B4R after send the array byte get error and restart.
error code:
B4X:
load 0x4010f000, len 3584, room 16
tail 0
chksum 0xb0
csum 0xb0
v2843a5ac
~ld

AppStart
ConnectToNetwork Local IP: 192.168.0.110

--------------- CUT HERE FOR EXCEPTION DECODER ---------------

Exception (9):
epc1=0x4020635a epc2=0x00000000 epc3=0x00000000 excvaddr=0x40202aef depc=0x00000000
>>>stack>>>
ctx: cont
sp: 3ffffd90 end: 3fffffc0 offset: 0190
3fffff20:  5300a8c0 00000066 3ffee390 402061d2 
3fffff30:  3ffee38c 00000000 3ffee3bc 40201090 
3fffff40:  40206888 6e00a8c0 3ffee3bc 3fffff68 
3fffff50:  00000000 3ffee358 3ffee3bc 40201cf2 
3fffff60:  3ffe8651 00000001 3ffe8644 3ffee54c 
3fffff70:  3fffdad0 3ffefaf4 3ffee374 40201a58 
3fffff80:  3fffdad0 3ffee37c 00000000 40201ac3 
3fffff90:  feefeffe 00000000 3ffee50c 40201f2f 
3fffffa0:  feefeffe feefeffe feefeffe 402043f8 
3fffffb0:  feefeffe feefeffe 3ffe84e8 40100bf9 
<<<stack<<<

--------------- CUT HERE FOR EXCEPTION DECODER ---------------

 ets Jan  8 2013,rst cause:4, boot mode:(3,6)
wdt reset
load 0x4010f000, len 3584, room 16
tail 0
chksum 0xb0
csum 0xb0
v2843a5ac
~ld
AppStart

my server code:
B4X:
'Non-UI application (console / server application)
#Region Project Attributes
    #CommandLineArgs:
    #MergeLibraries: True
#End Region

Sub Process_Globals
    Private bc As ByteConverter
    Private server As ServerSocket
    Private astream As AsyncStreams
End Sub

Sub AppStart (Args() As String)
    server.Initialize(17178, "server")
    server.Listen
    StartMessageLoop
End Sub

Sub server_NewConnection (Successful As Boolean, NewSocket As Socket)
    Log(Successful)
    If Successful Then
        If astream.IsInitialized Then astream.Close
        astream.InitializePrefix(NewSocket.InputStream,False, NewSocket.OutputStream, "astream")
        Wait For astream_NewData (Buffer() As Byte)
        Log("received: " & DateTime.GetSecond(DateTime.Now))
        Log(bc.StringFromBytes(Buffer,"UTF8"))
        Log(Buffer.Length)
        server.Listen
    Else
        Log(LastException)
    End If
End Sub

Sub astream_Error
    Log("Error: " & LastException)
    server.Listen
End Sub

B4R Client code:
B4X:
#Region Project Attributes
    #AutoFlushLogs: True
    #CheckArrayBounds: True
    #StackBufferSize: 600
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'Public variables can be accessed from all modules.
    Public Serial1 As Serial
    Private astream As AsyncStreams
    Public WiFi As ESP8266WiFi
    Private bc As ByteConverter
End Sub

Private Sub AppStart
    Serial1.Initialize(115200)
    Log("AppStart")
    ConnectToNetwork
End Sub


Sub Connect
    Dim sock As WiFiSocket
    sock.ConnectIP(Array As Byte(192, 168, 0, 83), 17178)
    If sock.Connected Then
        astream.InitializePrefix(sock.Stream,False, "astream_NewData", "astream_Error")
        astream.Write(bc.StringToBytes("ABCDEFG"))
    End If
    sock.Close
End Sub

Sub astream_Error
    Log("Error")
End Sub

Sub astream_NewData (Buffer() As Byte)
    
End Sub

Public Sub ConnectToNetwork
    WiFi.Disconnect
    If WiFi.Connect2("xxxx", "xxx") Then
        Log("ConnectToNetwork Local IP: ", WiFi.LocalIp)
        Connect
    Else
        Log("ConnectToNetwork Failed to connect.")
    End If
End Sub

and I upload small project, who can help me test, is it same errors.
 

Attachments

  • testing.zip
    8 KB · Views: 165
Top