Sub Process_Globals
Public Serial1 As Serial
Private wifi As WiFi101
Private const ssid As String = "dlink"
Private client As WiFiSocket
Private astream As AsyncStreams
Private timer1 As Timer
End Sub
Private Sub AppStart
Serial1.Initialize(115200)
Log("AppStart2")
ScanNetworks
If wifi.Connect(ssid) Then 'open network. Use ConnectWPA to connect to a secure network
ConnectToServer
End If
End Sub
Private Sub ConnectToServer
If client.ConnectIP(Array As Byte(192,168,0,6), 51042, False) Then
Log("Connected to server")
astream.Initialize(client.Stream, "astream_NewData", "astream_Error")
timer1.Initialize("timer1_Tick", 1000)
timer1.Enabled = True
End If
End Sub
Sub Timer1_Tick
Log("timer")
astream.Write(NumberFormat(Millis, 0, 0))
End Sub
Sub astream_NewData (Buffer() As Byte)
Log("newdata: ", Buffer)
End Sub
Sub astream_Error
Log("Error")
End Sub
Private Sub ScanNetworks
Log("Scanning for networks.")
Dim num As Int = wifi.ScanNetworks
Log("Found: ", num, " networks.")
For i= 0 To num - 1
Log("SSID: ", wifi.SSID(i), ", RSSI: ", wifi.RSSI(i), ", encryption type: ", wifi.EncryptionType(i))
Next
End Sub