public class networkSetup
{
public static networkSetup mInstance = new networkSetup();
- private static int MAX_TRY = 12;
+ private static int MAX_SCAN_TRY = 12;
+ private static int MAX_CONNECT_TRY = 3;
private networkSetup()
{
ap = WiFiManager.GetConnectedAP();
}
- for (int i = 0; i < MAX_TRY; i++) {
+ int connectTry = 0;
+ for (int i = 0; i < MAX_SCAN_TRY; i++) {
var list = WiFiManager.GetFoundAPs();
Tizen.Log.Info(Globals.LogTag, "Get Scan List. Try: " + i);
Tizen.Log.Info(Globals.LogTag, "Set passphrase");
item.SecurityInformation.SetPassphrase(WiFiPass);
}
- await item.ConnectAsync();
- Tizen.Log.Info(Globals.LogTag, "Connected");
- return;
+ try
+ {
+ await item.ConnectAsync();
+ Tizen.Log.Info(Globals.LogTag, "Connected");
+ return;
+ }
+ catch (System.Exception e)
+ {
+ /*
+ * It is possible that ConnectAsync is failed due to some network environment issue.
+ * In this case, we will try to connect the AP again.
+ */
+ if (connectTry == MAX_CONNECT_TRY)
+ {
+ Tizen.Log.Info(Globals.LogTag, "Failed to connect");
+ throw e;
+ }
+ else
+ {
+ connectTry++;
+ Tizen.Log.Info(Globals.LogTag, "Failed to connect --> try again after 3 seconds");
+ await Task.Delay(3000);
+ break;
+ }
+
+ }
}
}
if (i == 3)
await WiFiManager.ScanAsync();
}
await Task.Delay(10000);
- } // for (int i = 0; i < MAX_TRY; i++) {
+ } // for (int i = 0; i < MAX_SCAN_TRY; i++) {
} // if (ap != null && ap.NetworkInformation.Essid != WiFiName)
} // WiFiActivate()
}