I have the following setup:
A car driven by Arduino with B4R app, connected by SerialSoftware to ESP8266.
The ESP is used as Server in the lan and a B4A is trying to connect and establish Astream.
What I get is an error in the ESP and in the B4A on the lines of Astream init.
The codes, B4R ESP :
B4A:
The error log:
In the esp log I get:
I guess the B4A fails because of the ESP's astream error but I don't understand why.
Another astream works fine with the other B4R that runs on the Arduino.
Note: the same ESP in another setup connects as client to a B4j server and Astream init is successful there.
A car driven by Arduino with B4R app, connected by SerialSoftware to ESP8266.
The ESP is used as Server in the lan and a B4A is trying to connect and establish Astream.
What I get is an error in the ESP and in the B4A on the lines of Astream init.
The codes, B4R ESP :
B4X:
Sub Server_newConnection(NewSocket As WiFiSocket)
Log("new connection")
Wstream.Initialize(NewSocket.Stream,"Wstream_NewData", "Wstream_Error")
Server.Listen
End Sub
B4A:
B4X:
Sub connect
If sock.Connected Then
Log("Connected to Car")
Astream.Initialize(sock.InputStream, sock.OutputStream,"Astream")
conn.Background = dr1
Else
Log("Failed to connect to Car")
sock.Connect("192.168.0.160",54321,0)
connect
End If
End Sub
The error log:
** Activity (main) Pause, UserClosed = false **
** Service (starter) Create **
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
Failed to connect to Car
Failed to connect to Car
Failed to connect to Car
Connected to Car
Error occurred on line: 134 (Main)
java.net.SocketException: Socket is closed
at java.net.PlainSocketImpl.checkNotClosed(PlainSocketImpl.java:116)
at java.net.PlainSocketImpl.getInputStream(PlainSocketImpl.java:213)
at java.net.Socket.getInputStream(Socket.java:365)
at anywheresoftware.b4a.objects.SocketWrapper.getInputStream(SocketWrapper.java:220)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:703)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:337)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:247)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:134)
at derez.carwifi.main.afterFirstLayout(main.java:102)
at derez.carwifi.main.access$000(main.java:17)
at derez.carwifi.main$WaitForLayout.run(main.java:80)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
** Activity (main) Resume **
** Activity (main) Resume **
In the esp log I get:
new connection
Wstream Error
I guess the B4A fails because of the ESP's astream error but I don't understand why.
Another astream works fine with the other B4R that runs on the Arduino.
Note: the same ESP in another setup connects as client to a B4j server and Astream init is successful there.