public async Task GetDeviceNetworkInfo() { originalWifiNetwork = await wifiService.GetCurrentlyConnectedWifiNetwork(); if (!DeviceSetupService.SSIDIsEdisonDevice(originalWifiNetwork.SSID)) { deviceSetupService.OriginalSSID = originalWifiNetwork.SSID; await wifiService.ConnectToWifiNetwork(deviceSetupService.CurrentDeviceHotspotNetwork.SSID, deviceSetupService.WiFiPassword); } else { // wifi should already be defined CheckingConnectionStatusUpdated?.Invoke(this, new CheckingConnectionStatusUpdatedEventArgs(this.deviceSetupService.ConnectedWifiSSID)); } }
private void WifiService_CheckingConnectionStatusUpdated(object sender, Common.WiFi.CheckingConnectionStatusUpdatedEventArgs e) { if (e.IsConnected) { if (DeviceSetupService.SSIDIsEdisonDevice(e.SSID)) { onboardingRestService.SetBasicAuthentication(deviceSetupService.PortalPassword); Task.Run(async() => { var networks = await this.onboardingRestService.GetAvailableWifiNetworks(); if (networks != default(IEnumerable <Models.AvailableNetwork>)) { var connectedNetwork = networks.FirstOrDefault(i => i.AlreadyConnected); if (connectedNetwork != default(Models.AvailableNetwork)) { this.wifiService.CheckingConnectionStatusUpdated -= WifiService_CheckingConnectionStatusUpdated; this.deviceSetupService.ConnectedWifiSSID = connectedNetwork.SSID; CheckingConnectionStatusUpdated?.Invoke(this, new CheckingConnectionStatusUpdatedEventArgs(connectedNetwork.SSID)); } else { this.wifiService.CheckingConnectionStatusUpdated -= WifiService_CheckingConnectionStatusUpdated; CheckingConnectionStatusUpdated?.Invoke(this, new CheckingConnectionStatusUpdatedEventArgs("Device Not Using WiFi")); } } else { this.wifiService.CheckingConnectionStatusUpdated -= WifiService_CheckingConnectionStatusUpdated; CheckingConnectionStatusUpdated?.Invoke(this, new CheckingConnectionStatusUpdatedEventArgs("Device Not Connected To a Network")); } await wifiService.DisconnectFromWifiNetwork(new WifiNetwork() { SSID = e.SSID }); }); } else { Task.Run(async() => { await CompleteUpdate(); }); } } }
public async Task <bool> ConnectToWifiNetwork(string ssid, string passphrase) { try { var hotspotConfig = string.IsNullOrEmpty(passphrase) ? new NEHotspotConfiguration(ssid) : new NEHotspotConfiguration(ssid, passphrase, false); hotspotConfig.JoinOnce = true; await NEHotspotConfigurationManager.SharedManager.ApplyConfigurationAsync(hotspotConfig); CheckingConnectionStatusUpdated?.Invoke(this, new CheckingConnectionStatusUpdatedEventArgs($"Connected", ssid, true)); return(true); } catch (Exception e) { ConnectionFailed?.Invoke(this, new ConnectionFailedEventArgs("Failed to connect to hotspot")); logger.Log(e, "Failed to connect to hotspot"); return(false); } }
private async Task <bool> Connect(int networkId, string ssid) { if (networkId == -1) { ConnectionFailed?.Invoke(this, new ConnectionFailedEventArgs("Network wasn't found")); Console.WriteLine("Network Id was -1"); return(false); } StringBuilder stringBuilder = new StringBuilder(); bool connected; WifiInfo info = default(WifiInfo); int tryCount = 0; do { if (tryCount < 50) { stringBuilder.Append("."); CheckingConnectionStatusUpdated?.Invoke(this, new CheckingConnectionStatusUpdatedEventArgs($"Connecting{stringBuilder.ToString()}", ssid, false)); } else { ConnectionFailed?.Invoke(this, new ConnectionFailedEventArgs("Didn't connect quickly enough.")); return(false); } connected = wifiManager.EnableNetwork(networkId, true); await Task.Delay(500); tryCount++; info = wifiManager.ConnectionInfo; }while ((info.NetworkId != networkId || info.SupplicantState != SupplicantState.Completed)); CheckingConnectionStatusUpdated?.Invoke(this, new CheckingConnectionStatusUpdatedEventArgs($"Connected", ssid, true)); return(true); }
private void WifiService_ConnectionFailed(object sender, Common.WiFi.ConnectionFailedEventArgs e) { CheckingConnectionStatusUpdated?.Invoke(this, new CheckingConnectionStatusUpdatedEventArgs("Could not connect to device")); }