In a Serial (rs232) connection, commands of 3 bytes are sent to a PIC (microcontroller), byte by byte (just a one-byte buffer in the PIC), and echoed for timing. Tried a Delay(50) between the commands to give some time to the wifi stack, however, it fails after a few seconds. Without wifi activated (STA and AP mode) it works perfectly, so serial interrupts are lost?
B4X:
#Region Project Attributes
#AutoFlushLogs: True
#CheckArrayBounds: True
#StackBufferSize: 300
#End Region
Sub Process_Globals
Public Ser As Serial
Private wifi As ESP8266WiFi
Private udp As WiFiUDP
Private astream As AsyncStreams
Private cnt As Byte
End Sub
Private Sub AppStart
Dim d1(1) As Byte
wifi.Connect2(<ssid>,<psw>) 'more rs232 losses in AP mode
udp.Initialize(6000,"UDPrec")
Ser.Initialize(115200) : Delay(2000)
astream.Initialize(Ser.Stream, "RS232rec", Null)
astream.WaitForMoreDataDelay = 0 : Delay(1000)
d1(0) = 3 : astream.Write(d1)
End Sub
Sub RS232rec(buf() As Byte) : Dim d1(1) As Byte
cnt = (cnt + 1) Mod 3 'send sequence of 3 bytes to PIC
If cnt = 0 Then Delay(50) 'allow time for wifi stack, or yield()?
d1(0) = 3 : astream.Write(d1)
End Sub
Sub UDPrec(data() As Byte, IP() As Byte, Port As UInt)
'not used for the test
End Sub