Hi All!
I have Cobra 2 with WiFi, which work until the WiFi access point does not turn off, if for some reason it off and on, then connect to it can not restored by Cobra 2 and for this it is necessary to reboot for reconnection.
Maybe someone knows how to programmatically reconnect Cobra 2 to the WiFi access point (router) when connection loss.
Thanks.
I found the solution. May be useful to someone.
private static InitializeWifi()
{
wifi = new GHI.Premium.Net.WiFiRS9110(SPI.SPI_module.SPI2, GHI.Premium.Hardware.G120.Pin.P1_10, GHI.Premium.Hardware.G120.Pin.P2_11, GHI.Premium.Hardware.G120.Pin.P1_9, 4000);
wifi.Open();
// ...
Thread wificon = new Thread(WiFiConnect);
wificon.Start();
// Set handle on connection change
wifi.WirelessConnectivityChanged += new GHI.Premium.Net.WiFiRS9110.WirelessConnectivityChangedEventHandler(wifi_WirelessConnectivityChanged);
}
private static void WiFiConnect()
{
GHI.Premium.Net.WiFiNetworkInfo[] scanResults;
while (!wifi.IsLinkConnected)
{
scanResults = wifi.Scan();
if (scanResults != null)
{
foreach (GHI.Premium.Net.WiFiNetworkInfo network in scanResults)
{
if (network.SSID == "network")
{
wifi.Join(network, "password");
break;
}
}
}
Thread.Sleep(3000);
}
}
static void wifi_WirelessConnectivityChanged(object sender, GHI.Premium.Net.WiFiRS9110.WirelessConnectivityEventArgs e)
{
if (!e.IsConnected)
{
WiFiConnect();
}
}