#Region Project Attributes
#AutoFlushLogs: True
#CheckArrayBounds: True
#StackBufferSize: 300
#End Region
Sub Process_Globals
Public Serial1 As Serial
Private wifi As ESP8266WiFi
Private client As WiFiSocket
Private astream As AsyncStreams
Private timer1 As Timer
'Private serverIp() As Byte = Array As Byte(192, 168, 178, 30) 'PC
'Private serverIp() As Byte = Array As Byte(192, 168, 178, 29) 'Samsung-S4
Private serverIp() As Byte = Array As Byte(192,168,178,96) 'Nokia G20
End Sub
Private Sub AppStart
Serial1.Initialize(115200)
Log("AppStart")
'ScanNetworks
If wifi.Connect2("ssid","password") Then 'change to your network SSID (use Connect2 if a password is required).
Log("Connected to wireless network.")
Else
Log("Failed to connect.")
Return
End If
timer1.Initialize("timer1_Tick", 1000)
timer1.Enabled = True
Connect(0)
End Sub
Sub Timer1_Tick
If client.Connected Then
astream.Write("Time here is: ").Write(NumberFormat(Millis, 0, 0))
End If
End Sub
Private Sub Connect(u As Byte)
If client.ConnectIP(serverIp, 51042) Then
Log("Connected to server.")
astream.Initialize(client.Stream, "astream_NewData", "astream_Error")
Else
Log("Failed to connect to server")
CallSubPlus("Connect", 1000, 0)
End If
End Sub
Sub AStream_NewData (Buffer() As Byte)
Log("Received: ", Buffer)
End Sub
Sub AStream_Error
Log("Error")
CallSubPlus("Connect", 1000, 0)
End Sub
Private Sub ScanNetworks 'ignore
Dim numberOfNetworks As Byte = wifi.Scan
Log("Found: ", numberOfNetworks, " networks.")
For i = 0 To numberOfNetworks - 1
Log(wifi.ScannedSSID(i))
Next
End Sub