private async void ScanForWiFiAdaptersAsync() { if (m_wiFiAdapter == null) { UpdateStatusAsync("Requesting WiFi access...", NotifyType.StatusMessage); WiFiAccessStatus accessStatus = await WiFiAdapter.RequestAccessAsync(); if (accessStatus != WiFiAccessStatus.Allowed) { UpdateStatusAsync("WiFi access denied.", NotifyType.ErrorMessage); } else { m_wiFiAdapterList = await WiFiAdapter.FindAllAdaptersAsync(); if (m_wiFiAdapterList.Count > 0) { for (int i = 0; i < m_wiFiAdapterList.Count; i++) { m_wiFiAdapterDisplayNames.Add(string.Format("Adapter {0}", (i + 1))); } WiFiAdapterListVisibility = Visibility.Visible; UpdateStatusAsync("Please select a WiFi adapter.", NotifyType.StatusMessage); } else { UpdateStatusAsync("No WiFi adapters detected on this machine.", NotifyType.ErrorMessage); } } } }
public async Task <int> Initialize() { if (m_wiFiAdapter == null) { //Request access of WiFi adapter. WiFiAccessStatus accessStatus = await WiFiAdapter.RequestAccessAsync(); if (accessStatus != WiFiAccessStatus.Allowed) { rootPage.Log("NETWORK_MANAGER::[ERROR]ScanForWiFiAdapterAsync: WiFi access denied."); } else { //Find WiFi adatper m_wiFiAdapterList = await WiFiAdapter.FindAllAdaptersAsync(); rootPage.Log("NETWORK_MANAGER::Found " + m_wiFiAdapterList.Count + " wifi adapter."); while (m_wiFiAdapterList.Count < 1) { await System.Threading.Tasks.Task.Delay(3000); m_wiFiAdapterList = await WiFiAdapter.FindAllAdaptersAsync(); rootPage.Log("NETWORK_MANAGER::Found " + m_wiFiAdapterList.Count + " wifi adapter."); } //Get the first WiFi adatper from the list. //TODO: Edit this part if the system has more than one WiFi adatpers. m_wiFiAdapter = m_wiFiAdapterList[0]; } return(-1); } return(0); }
/// <summary> /// Инициализация адаптера /// </summary> /// <returns></returns> private async Task <bool> InitializeFirstAdapter() { return(await Task.Run(async() => { if (_wifiAdapter == null) { bool res = false; WiFiAccessStatus access = await WiFiAdapter.RequestAccessAsync(); if (access != WiFiAccessStatus.Allowed) { throw new Exception("WiFiAccessStatus not allowed"); } else { var wifiAdapterResults = await DeviceInformation.FindAllAsync(WiFiAdapter.GetDeviceSelector()); if (wifiAdapterResults.Count >= 1) { _wifiAdapter = await WiFiAdapter.FromIdAsync(wifiAdapterResults[0].Id); res = true; } else { throw new Exception("WiFi Adapter not found."); } } return res; } else { return true; } })); }
private async Task <bool> _getNetworks() { WiFiAccessStatus access = await WiFiAdapter.RequestAccessAsync(); if (access != WiFiAccessStatus.Allowed) { _done = true; return(false); } else { DeviceInformationCollection adapterResults = await DeviceInformation.FindAllAsync(WiFiAdapter.GetDeviceSelector()); if (adapterResults.Count() >= 1) { _WiFiAdapter = await WiFiAdapter.FromIdAsync(adapterResults[0].Id); } else { _done = true; return(false); } } await _WiFiAdapter.ScanAsync(); foreach (WiFiAvailableNetwork availableNetwork in _WiFiAdapter.NetworkReport.AvailableNetworks) { _WiFiNetworks.Add(availableNetwork.Ssid); } return(true); }
public async Task RequestWifiAccess() { try { wiFiaccess = await WiFiAdapter.RequestAccessAsync(); } catch (Exception ex) { Debug.WriteLine("RequestWifiAccess() Exception: " + ex.Message); throw; } }
protected override async void OnNavigatedTo(NavigationEventArgs e) { // RequestAccessAsync must have been called at least once by the app before using the API // Calling it multiple times is fine but not necessary // RequestAccessAsync must be called from the UI thread WiFiAccessStatus access = await WiFiConnector.Instance.RequestAccessAsync(); if (access != WiFiAccessStatus.Allowed) { //await UIMessager.Instance.ShowMessageAndWaitForFeedback("WiFi Config", "WiFi access is disallowed for this device!", UIMessageButtons.OK, UIMessageType.Information); } else { if (!await WiFiConnector.Instance.Init()) { //await UIMessager.Instance.ShowMessageAndWaitForFeedback("WiFi Config", "No WiFi Adapters detected on this device!", UIMessageButtons.OK, UIMessageType.Information); } } }
private async Task <bool> _getWifiAdapter() { WiFiAccessStatus access = await WiFiAdapter.RequestAccessAsync(); if (access != WiFiAccessStatus.Allowed) { throw new Exception("WiFiAccessStatus not allowed."); } else { DeviceInformationCollection adapterResults = await DeviceInformation.FindAllAsync(WiFiAdapter.GetDeviceSelector()); if (adapterResults.Count() >= 1) { _WiFiAdapter = await WiFiAdapter.FromIdAsync(adapterResults[0].Id); } else { throw new Exception("WiFi adapter not found."); } } return(true); }
private async void Button_Click_1(object sender, RoutedEventArgs e) { Windows.Storage.Pickers.FileSavePicker savePicker = new Windows.Storage.Pickers.FileSavePicker(); savePicker.FileTypeChoices.Add("Plain Text", new List <string>() { ".txt" }); Windows.Storage.StorageFile file = await savePicker.PickSaveFileAsync(); sb.AppendLine("time;ssid1;strength1;ssid2;strength2;ssid3;strength3;ssid4;strength4;ssid5;strength5"); WiFiAccessStatus access = await WiFiAdapter.RequestAccessAsync(); DateTimeOffset time = DateTimeOffset.Now; sb.AppendLine(time.ToString() + time.Millisecond); if (access == WiFiAccessStatus.Allowed) { DataContext = this; var result = await Windows.Devices.Enumeration.DeviceInformation.FindAllAsync(WiFiAdapter.GetDeviceSelector()); //time = DateTimeOffset.Now; //sb.AppendLine(time.ToString() + time.Millisecond); if (result.Count >= 1) { wifiAdapter = await WiFiAdapter.FromIdAsync(result[0].Id); //time = DateTimeOffset.Now; //sb.AppendLine(time.ToString() + time.Millisecond); } } time = DateTimeOffset.Now; //sb.AppendLine(time.ToString() + time.Millisecond); var result1 = await WiFiAdapter.FindAllAdaptersAsync(); sb.AppendLine(result1.GetType().ToString()); while (true) { var firstadapter = result1[0]; await firstadapter.ScanAsync(); time = DateTimeOffset.Now; //await Task.Delay(5000); sb.Append(" " + time.Hour + ":" + time.Minute + ":" + time.Second + ":" + time.Millisecond + " ; "); // List<string> sortedList = new List<string>(); foreach (var network in firstadapter.NetworkReport.AvailableNetworks) { //var _dist = Math.Pow(10, 0.05 * (-20 * Math.Log10(network.ChannelCenterFrequencyInKilohertz / 1000) + 27.55 + Math.Abs(network.NetworkRssiInDecibelMilliwatts))); //ls.Add(Math.Round(_dist, 1) + "m " + " Name : " + network.Ssid + " , dB signal RSSID : " + network.NetworkRssiInDecibelMilliwatts+network.Uptime.ToString(@"\:mm\:ss\:fff")); sb.Append(network.Ssid + " ; " + network.NetworkRssiInDecibelMilliwatts + " ; " + network.Bssid + " ; " + network.ChannelCenterFrequencyInKilohertz + " ; "); } sb.AppendLine(); messageb.Text = sb.ToString(); //connectpanel.Visibility = Visibility.Collapsed; await Windows.Storage.FileIO.WriteTextAsync(file, sb.ToString()); //sortedList = ls.OrderBy(s => double.Parse(s.Substring(0, s.IndexOf('m')))).ToList(); } }