Sub Process_Globals
Public Serial1 As Serial
Private wifi As ESP8266WiFi
Private socket As WiFiSocket
Private astream As AsyncStreams
End Sub
Private Sub AppStart
Serial1.Initialize(115200)
Log("AppStart")
RunNative("SetSTA", Null)
Log(wifi.Connect("esp_server"))
Log(wifi.LocalIp)
Connect(0)
End Sub
Sub Connect(u As Byte)
Log("Trying to connect")
If socket.ConnectIP(Array As Byte(192, 168, 0, 3), 51042) Then
Log("connected")
astream.InitializePrefix(socket.Stream, False, "astream_NewData", "astream_Error")
astream.Write("hello!!!")
Else
CallSubPlus("Connect", 1000, 0)
End If
End Sub
#if C
void SetSTA(B4R::Object* o) {
WiFi.mode(WIFI_STA);
}
#end if
Sub astream_NewData (Buffer() As Byte)
Log("new data: ", Buffer)
End Sub
Sub astream_Error
Log("error")
End Sub