Hi all,
in my 3D printer host app I've a problem than cannot know how to solve.
I'm explain better...
My app communicate over TCP socket with ESP8266 / ESP32 to control a 3D printer, it send and
receive commands. ESP act as server and as WiFi<->Serial bridge, my app as client and connect to ESP.
Because the ESP sketch in written in C++ I avoided to use a stream in Prefix mode and used the standard way,
this forced me to collect on both side the data, not simple in C++ but after a lots of changes worked well.
I do not used AstreamText because I reuse the same socket to send string commands and even to upload
gcode files (as binary data) from Android to ESP SD Card, I just replicated what AstreamText do using a StringBuilder to collect data and CRLF as delimiter, only on the send command sub (strings).
Every command I send to ESP it send to a 3D printer, ESP read response from 3D printer and return back (the original command and reply from 3D printer) to Android as log.
My problem is that when I connect to ESP, ESP send a command to a printer to request the temperature, then send it back to Android that read it and draw a temperature graph.
If in my app I do some things, eg, I call a Sub that send over socket, it send and then the sub Astream_NewData is fired without that my sub finish to execute, this is a reply from ESP that arrives.
I want to know if there is a way to deactivate for some time the data reception, eg when I upload a file to ESP. I tried to add a boolean flag but without success.
Better explained with code:
Many thanks
in my 3D printer host app I've a problem than cannot know how to solve.
I'm explain better...
My app communicate over TCP socket with ESP8266 / ESP32 to control a 3D printer, it send and
receive commands. ESP act as server and as WiFi<->Serial bridge, my app as client and connect to ESP.
Because the ESP sketch in written in C++ I avoided to use a stream in Prefix mode and used the standard way,
this forced me to collect on both side the data, not simple in C++ but after a lots of changes worked well.
I do not used AstreamText because I reuse the same socket to send string commands and even to upload
gcode files (as binary data) from Android to ESP SD Card, I just replicated what AstreamText do using a StringBuilder to collect data and CRLF as delimiter, only on the send command sub (strings).
Every command I send to ESP it send to a 3D printer, ESP read response from 3D printer and return back (the original command and reply from 3D printer) to Android as log.
My problem is that when I connect to ESP, ESP send a command to a printer to request the temperature, then send it back to Android that read it and draw a temperature graph.
If in my app I do some things, eg, I call a Sub that send over socket, it send and then the sub Astream_NewData is fired without that my sub finish to execute, this is a reply from ESP that arrives.
I want to know if there is a way to deactivate for some time the data reception, eg when I upload a file to ESP. I tried to add a boolean flag but without success.
Better explained with code:
B4X:
' Dim Success As Boolean = SendCommand("MyCommand")
Wait For (SendCommand("MyCommand")) Complete (Success As Boolean)
If Success Then ...
'....
'....
Sub SendCommand(cmd As String) As Boolean
Wait For (SendSocket(cmd)) Complete (Success as Boolean) ' >>> SEND DATA
If Success Then ' This piece of code is never called because SocketAStreams_NewData is called before, then the code do not continue here
Log("SUCCESS")
Else
Log("Cannot send data, queed is full")
End Sub
Return Success
End Sub
Sub SendSocket (cmd As String) As ResumableSub
Return SocketAStreams.Write(cmd.GetBytes("UTF8"))
End Sub
Sub SocketAStreams_NewData (Buffer() As Byte) ' <<< RECEIVE DATA
[read and collect data]
End Sub
Many thanks
Last edited: