Private Sub Server_NewConnection (NewSocket As WiFiSocket)
Astream.Initialize(NewSocket.Stream,"Astream_NewData", "Astream_Error")
Astream.WaitForMoreDataDelay = 200
Astream.MaxBufferSize = 100
timer1.Enabled = True
End Sub
Sub Timer1_Tick
Astream.Initialize(Main.Serial1.Stream, "Astream_NewData", Null)'<---------------i just added this line'
End Sub
Private Sub Astream_NewData (Buffer() As Byte)
Log(Buffer)
If bc.IndexOf(Buffer, "GET") <> -1 Then
If bc.IndexOf(Buffer, "/set") <> -1 Then
Dim ssid = "", password = "" As String
Dim i1 As Int = 0
Dim i2 As Int = 0
For Each b1() As Byte In bc.Split(Buffer, " ")
If i1 = 1 Then
For Each b2() As Byte In bc.Split(b1, "/")
Select i2
Case 2
ssid = bc.StringFromBytes(b2)
Case 3
password = bc.StringFromBytes(b2)
End Select
i2 = i2 + 1
Next
End If
i1 = i1 + 1
Next
Log(StackBufferUsage)
Astream.Write("HTTP/1.1 200").Write(CRLF)
Astream.Write("Content-Type: text/html").Write(CRLF).Write(CRLF)
Astream.Write("<script>setTimeout(function(){location.href=""http://192.168.4.1""} , 20000);</script>")
Astream.Write("WiFi set to: ").Write(ssid).Write(", password: ").Write(password).Write("<br/>Please wait...")
Main.SaveNetworkDetails(ssid, password)
CallSubPlus("ConnectWifi", 500, 0)
Else If bc.IndexOf(Buffer, " / ") <> -1 Then
Astream.Write("HTTP/1.1 200").Write(CRLF).Write(CRLF)
If Main.WiFi.IsConnected Then
Astream.Write("Connected to network.").Write(CRLF)
Astream.Write("ESP8266 IP address: ").Write(Main.WiFi.LocalIp)
Else
Astream.Write("Not connected!")
End If
Else
Astream.Write("HTTP/1.1 404").Write(CRLF)
End If
CallSubPlus("CloseConnection", 200, 0)
End If
End Sub
Sub Astream_Data(data() As Byte)
Astream.Write(data)
End Sub
Private Sub AStream_Error
Log("Disconnected")
server.Listen
timer1.Enabled = False
End Sub
Private Sub ConnectWifi(u As Byte)
Main.ConnectToNetwork
End Sub
Private Sub CloseConnection(u As Byte)
Log("close connection")
If server.Socket.Connected Then
server.Socket.Stream.Flush
server.Socket.Close
End If
End Sub