Sub Process_Globals
Public Serial1 As Serial
Private wifi As ESP8266WiFi
Private astream As AsyncStreams
Private socket As WiFiSocket
End Sub
Private Sub AppStart
Serial1.Initialize(115200)
Log("AppStart")
If wifi.Connect("dlink") Then 'change as needed
Log("Connected to router")
Else
Log("Failed to connect")
Return
End If
Connect(0)
End Sub
Sub Connect(unused As Byte)
If socket.ConnectHost("example.com", 80) = False Then
Log("trying to connect again")
CallSubPlus("Connect", 1000, 0)
Return
End If
Log("Connected to server")
astream.Initialize(socket.Stream, "Astream_NewData", "Astream_Error")
Dim eol() As Byte = Array As Byte(13, 10)
astream.Write("GET / HTTP/1.1".GetBytes)
astream.Write(eol)
astream.Write("Host: www.example.com".GetBytes)
astream.Write(eol)
astream.Write("Connection: close".GetBytes)
astream.Write(eol)
astream.Write(eol)
End Sub
Sub Astream_NewData (Buffer() As Byte)
Log(Buffer)
End Sub
Sub Astream_Error
Log("Disconnected")
End Sub