'loops = 1 to 250. > 250 = infinite loops. 0 = do nothing
private Sub RouterConnectAsync(Loops As Byte)
If Loops = 0 Then
ReceiveWatchdog.Enabled = True
Return 'do nothing or 'loop countdown' has reached 0
End If
ReconnectLoops = Loops
Dim SSID As String = ReadSSID
Dim Password As String = ReadP
watchstart2 = Millis
Main.eWiFi.ConnectAsync(SSID, Password, 0, Null, "wifi_Connected")
' Delay(3000)
' Dim x As Boolean = Main.eWiFi.Connect2(SSID, Password)
' If x Then
' WiFi_Connected(True)
' Else
' WiFi_Connected(False)
' End If
End Sub
Sub WiFi_Connected(Success As Boolean)
Log("WiFi_Connected: ", Success, " after: ", (Millis - watchstart2), "mS")
If Success Then
SetFixedIP(ReadClientIP) 'in case the router tries to change the IP
AsyncReceiveServer.Listen
ReceiveWatchdog.Enabled = True
Return
End If
'loop, waiting for wifi
If ReconnectLoops > 250 Then
CallSubPlus("RouterConnectAsync", 1000, ReconnectLoops) 'infinite tries
Else
CallSubPlus("RouterConnectAsync", 1000, (ReconnectLoops - 1)) 'loop tries
End If
End Sub
Sub ReceiveWatchdog_Tick
Log("Receive WDOG Tick")
ReceiveWatchdog.Enabled = False
If Not(Main.eWiFi.IsConnected) Then
CallSubPlus("RouterConnectAsync", 1, 255) 'infinite tries
Else
ReceiveWatchdog.Enabled = True
End If
End Sub