#Region Project Attributes
#AutoFlushLogs: True
#CheckArrayBounds: True
#StackBufferSize: 300
#End Region
Sub Process_Globals
'These global variables will be declared once when the application starts.
'Public variables can be accessed from all modules.
Public Serial1 As Serial
Private astream As AsyncStreams
Private wifi As ESP8266WiFi
Private server As WiFiServerSocket
Private fs As ESP8266FileSystem
Private sslsocket As WiFiSSLSocket
End Sub
Private Sub AppStart
Serial1.Initialize(115200)
Log("AppStart")
Log("Available RAM at App start: ",AvailableRAM)
Log("FS Initialize result: ", fs.Initialize())
Log("Available RAM after fs: ",AvailableRAM)
If wifi.Connect2("xyz","123456789") = False Then
Log("Error connecting to network")
Return
Else
Log("Connected to network")
End If
server.Initialize(80, "server_NewConnection")
server.Listen
Log("Available RAM after server init: ",AvailableRAM)
Dim st As Stream = Null
sslsocket.Close
If sslsocket.ConnectHost("www.google.com",443) Then
Log("Connected to google")
st = sslsocket.Stream
Else
Log("Failed to connect to Google")
End If
Log("Available RAM after ssl connect: ",AvailableRAM)
End Sub
Sub Server_NewConnection (NewSocket As WiFiSocket)
astream.Initialize(NewSocket.Stream, "astream_NewData", "astream_Error")
End Sub
Sub Astream_NewData (Buffer() As Byte)
Header
astream.Write("Hello World, the quick brown fox jumped over the lazy dog").Write(CRLF)
astream.Write("</body>").Write(CRLF)
astream.Write("</html>").Write(CRLF)
CallSubPlus("CloseConnection",200,0)
End Sub
Private Sub Header()
astream.Write("HTTP/1.1 200").Write(CRLF)
astream.Write("Content-Type: text/html").Write(CRLF).Write(CRLF)
astream.Write("<!DOCTYPE html>").Write(CRLF)
astream.Write("<html>").Write(CRLF)
astream.Write("<head>").Write(CRLF)
astream.Write("<style>").Write(CRLF)
astream.Write("body {margin-top: 12%; background-color:lightgray; font-family:Helvetica; Font-size:350%; }").Write(CRLF)
astream.Write("input[type=text] {font-family:Helvetica; Font-size:120%}").Write(CRLF)
astream.Write("</style>").Write(CRLF)
astream.Write("</head>").Write(CRLF)
astream.Write("<body>").Write(CRLF)
End Sub
Private Sub CloseConnection(u As Byte)
server.Socket.Close
End Sub
Sub Astream_Error
server.Listen
End Sub