private void GetWIFIProfileComplete(string result) { Debug.Log(result); WifiInterfaces all = JsonUtil.Deserialize <WifiInterfaces>(result); List <string> profileName = new List <string>(); for (int i = 0; i < all.Interfaces.Count; i++) { WifiInterface inter = all.Interfaces[i]; string uid = inter.GUID; uid = uid.Trim(); uid = uid.Substring(1, uid.Length - 2); Debug.Log("find uid=" + uid); Debug.Log("networkId=" + networkID); if (uid == networkID) { for (int j = 0; j < inter.ProfilesList.Count; j++) { WifiProfile profile = inter.ProfilesList[j]; profileName.Add(profile.Name); } Debug.Log("Find!!! profile count=" + profileName.Count); } } panel.hololensStatusPanel.ShowWifiProfileResult(profileName); }
/// <summary> /// Click handler for the getWifiInfo button. /// </summary> /// <param name="sender">The caller of this method.</param> /// <param name="e">The arguments associated with this event.</param> private async void GetWifiInfo_Click(object sender, RoutedEventArgs e) { this.ClearOutput(); this.EnableConnectionControls(false); this.EnableDeviceControls(false); StringBuilder sb = new StringBuilder(); sb.Append(commandOutput.Text); sb.AppendLine("Getting WiFi interfaces and networks..."); commandOutput.Text = sb.ToString(); try { WifiInterfaces wifiInterfaces = await portal.GetWifiInterfacesAsync(); sb.AppendLine("WiFi Interfaces:"); foreach (WifiInterface wifiInterface in wifiInterfaces.Interfaces) { sb.Append(" "); sb.AppendLine(wifiInterface.Description); sb.Append(" GUID: "); sb.AppendLine(wifiInterface.Guid.ToString()); WifiNetworks wifiNetworks = await portal.GetWifiNetworksAsync(wifiInterface.Guid); sb.AppendLine(" Networks:"); foreach (WifiNetworkInfo network in wifiNetworks.AvailableNetworks) { sb.Append(" SSID: "); sb.AppendLine(network.Ssid); sb.Append(" Profile name: "); sb.AppendLine(network.ProfileName); sb.Append(" is connected: "); sb.AppendLine(network.IsConnected.ToString()); sb.Append(" Channel: "); sb.AppendLine(network.Channel.ToString()); sb.Append(" Authentication algorithm: "); sb.AppendLine(network.AuthenticationAlgorithm); sb.Append(" Signal quality: "); sb.AppendLine(network.SignalQuality.ToString()); } } ; } catch (Exception ex) { sb.AppendLine("Failed to get WiFi info."); sb.AppendLine(ex.GetType().ToString() + " - " + ex.Message); } commandOutput.Text = sb.ToString(); EnableDeviceControls(true); EnableConnectionControls(true); }
private static async Task <Dictionary <string, string> > WifiNetworkToDico(Dictionary <string, string> returnedInfo, WifiInterfaces wifiInterfaces) { WifiNetworks wifiNetworkInfo = await GetInfo <WifiNetworks>(API_COMMAND_WIFI_NETWORKS, API_COMMAND_WIFI_NETWORKS_PARAMETER + wifiInterfaces.Interfaces[0].Guid); foreach (WifiNetworkInfo item in wifiNetworkInfo.AvailableNetworks) { if (item.IsConnected) { returnedInfo.Add("Connected Wifi", item.Ssid); } } return(returnedInfo); }
/// <summary> /// Connects to the device pointed to by IDevicePortalConnection provided in the constructor. /// </summary> /// <param name="ssid">Optional network SSID.</param> /// <param name="ssidKey">Optional network key.</param> /// <param name="updateConnection">Indicates whether we should update this connection's IP address after connecting.</param> /// <param name="manualCertificate">A manually provided X509 Certificate for trust validation against this device.</param> /// <remarks>Connect sends ConnectionStatus events to indicate the current progress in the connection process. /// Some applications may opt to not register for the ConnectionStatus event and await on Connect.</remarks> /// <returns>Task for tracking the connect.</returns> public async Task ConnectAsync( string ssid = null, string ssidKey = null, bool updateConnection = false, X509Certificate2 manualCertificate = null) { this.ConnectionHttpStatusCode = HttpStatusCode.OK; string connectionPhaseDescription = string.Empty; if (manualCertificate != null) { this.SetManualCertificate(manualCertificate); } try { // Get the device family and operating system information. connectionPhaseDescription = "Requesting operating system information"; this.SendConnectionStatus( DeviceConnectionStatus.Connecting, DeviceConnectionPhase.RequestingOperatingSystemInformation, connectionPhaseDescription); this.deviceConnection.Family = await this.GetDeviceFamilyAsync().ConfigureAwait(false); this.deviceConnection.OsInfo = await this.GetOperatingSystemInformationAsync().ConfigureAwait(false); // Default to using whatever was specified in the connection. bool requiresHttps = this.IsUsingHttps(); // HoloLens is the only device that supports the GetIsHttpsRequired method. if (this.deviceConnection.OsInfo.Platform == DevicePortalPlatforms.HoloLens) { // Check to see if HTTPS is required to communicate with this device. connectionPhaseDescription = "Checking secure connection requirements"; this.SendConnectionStatus( DeviceConnectionStatus.Connecting, DeviceConnectionPhase.DeterminingConnectionRequirements, connectionPhaseDescription); requiresHttps = await this.GetIsHttpsRequiredAsync().ConfigureAwait(false); } // Connect the device to the specified network. if (!string.IsNullOrWhiteSpace(ssid)) { connectionPhaseDescription = string.Format("Connecting to {0} network", ssid); this.SendConnectionStatus( DeviceConnectionStatus.Connecting, DeviceConnectionPhase.ConnectingToTargetNetwork, connectionPhaseDescription); WifiInterfaces wifiInterfaces = await this.GetWifiInterfacesAsync().ConfigureAwait(false); // TODO - consider what to do if there is more than one wifi interface on a device await this.ConnectToWifiNetworkAsync(wifiInterfaces.Interfaces[0].Guid, ssid, ssidKey).ConfigureAwait(false); } // Get the device's IP configuration and update the connection as appropriate. if (updateConnection) { connectionPhaseDescription = "Updating device connection"; this.SendConnectionStatus( DeviceConnectionStatus.Connecting, DeviceConnectionPhase.UpdatingDeviceAddress, connectionPhaseDescription); bool preservePort = true; // HoloLens and Mobile are the only devices that support USB. // They require the port to be changed when the connection is updated // to WiFi. if ((this.Platform == DevicePortalPlatforms.HoloLens) || (this.Platform == DevicePortalPlatforms.Mobile)) { preservePort = false; } this.deviceConnection.UpdateConnection( await this.GetIpConfigAsync().ConfigureAwait(false), requiresHttps, preservePort); } this.SendConnectionStatus( DeviceConnectionStatus.Connected, DeviceConnectionPhase.Idle, "Device connection established"); } catch (Exception e) { DevicePortalException dpe = e as DevicePortalException; if (dpe != null) { this.ConnectionHttpStatusCode = dpe.StatusCode; this.ConnectionFailedDescription = dpe.Message; } else { this.ConnectionHttpStatusCode = HttpStatusCode.Conflict; // Get to the innermost exception for our return message. Exception innermostException = e; while (innermostException.InnerException != null) { innermostException = innermostException.InnerException; await Task.Yield(); } this.ConnectionFailedDescription = innermostException.Message; } this.SendConnectionStatus( DeviceConnectionStatus.Failed, DeviceConnectionPhase.Idle, string.Format("Device connection failed: {0}, {1}", connectionPhaseDescription, this.ConnectionFailedDescription)); } }
/// <summary> /// Connects to the device pointed to by IDevicePortalConnection provided in the constructor. /// </summary> /// <param name="ssid">Optional network SSID.</param> /// <param name="ssidKey">Optional network key.</param> /// <param name="updateConnection">Indicates whether we should update this connection's IP address after connecting.</param> /// <remarks>Connect sends ConnectionStatus events to indicate the current progress in the connection process. /// Some applications may opt to not register for the ConnectionStatus event and await on Connect.</remarks> /// <returns>Task for tracking the connect.</returns> public async Task Connect( string ssid = null, string ssidKey = null, bool updateConnection = true) { #if WINDOWS_UWP this.ConnectionHttpStatusCode = HttpStatusCode.Ok; #else this.ConnectionHttpStatusCode = HttpStatusCode.OK; #endif // WINDOWS_UWP string connectionPhaseDescription = string.Empty; try { // Get the device family and operating system information. connectionPhaseDescription = "Requesting operating system information"; this.SendConnectionStatus( DeviceConnectionStatus.Connecting, DeviceConnectionPhase.RequestingOperatingSystemInformation, connectionPhaseDescription); this.deviceConnection.Family = await this.GetDeviceFamily(); this.deviceConnection.OsInfo = await this.GetOperatingSystemInformation(); // Default to using HTTPS. bool requiresHttps = true; // HoloLens is the only device that supports the GetIsHttpsRequired method. if (this.deviceConnection.OsInfo.Platform == DevicePortalPlatforms.HoloLens) { // Check to see if HTTPS is required to communicate with this device. connectionPhaseDescription = "Checking secure connection requirements"; this.SendConnectionStatus( DeviceConnectionStatus.Connecting, DeviceConnectionPhase.DeterminingConnectionRequirements, connectionPhaseDescription); requiresHttps = await this.GetIsHttpsRequired(); } // Connect the device to the specified network. if (!string.IsNullOrWhiteSpace(ssid)) { connectionPhaseDescription = string.Format("Connecting to {0} network", ssid); this.SendConnectionStatus( DeviceConnectionStatus.Connecting, DeviceConnectionPhase.ConnectingToTargetNetwork, connectionPhaseDescription); WifiInterfaces wifiInterfaces = await this.GetWifiInterfaces(); // TODO - consider what to do if there is more than one wifi interface on a device await this.ConnectToWifiNetwork(wifiInterfaces.Interfaces[0].Guid, ssid, ssidKey); } // Get the device's IP configuration and update the connection as appropriate. if (updateConnection) { connectionPhaseDescription = "Updating device connection"; this.SendConnectionStatus( DeviceConnectionStatus.Connecting, DeviceConnectionPhase.UpdatingDeviceAddress, connectionPhaseDescription); this.deviceConnection.UpdateConnection(await this.GetIpConfig(), requiresHttps); } this.SendConnectionStatus( DeviceConnectionStatus.Connected, DeviceConnectionPhase.Idle, "Device connection established"); } catch (Exception e) { DevicePortalException dpe = e as DevicePortalException; if (dpe != null) { this.ConnectionHttpStatusCode = dpe.StatusCode; this.ConnectionFailedDescription = dpe.Message; } else { this.ConnectionHttpStatusCode = HttpStatusCode.Conflict; // Get to the innermost exception for our return message. Exception innermostException = e; while (innermostException.InnerException != null) { innermostException = innermostException.InnerException; } this.ConnectionFailedDescription = innermostException.Message; } this.SendConnectionStatus( DeviceConnectionStatus.Failed, DeviceConnectionPhase.Idle, string.Format("Device connection failed: {0}, {1}", connectionPhaseDescription, this.ConnectionFailedDescription)); } }
/// <summary> /// Connects to the device pointed to by IDevicePortalConnection provided in the constructor. /// </summary> /// <param name="ssid">Optional network SSID.</param> /// <param name="ssidKey">Optional network key.</param> /// <param name="updateConnection">Indicates whether we should update this connection's IP address after connecting.</param> /// <param name="rawManualCertificate">Allows specifying the raw certificate manually. This allows loading it from a local file or loading an override for a web proxy.</param> /// <remarks>Connect sends ConnectionStatus events to indicate the current progress in the connection process. /// Some applications may opt to not register for the ConnectionStatus event and await on Connect.</remarks> /// <returns>Task for tracking the connect.</returns> public async Task Connect( string ssid = null, string ssidKey = null, bool updateConnection = true, byte[] rawManualCertificate = null) { #if WINDOWS_UWP this.ConnectionHttpStatusCode = HttpStatusCode.Ok; #else this.ConnectionHttpStatusCode = HttpStatusCode.OK; #endif // WINDOWS_UWP string connectionPhaseDescription = string.Empty; try { // Get the device certificate bool certificateAcquired = false; if (rawManualCertificate == null) { try { connectionPhaseDescription = "Acquiring device certificate"; this.SendConnectionStatus( DeviceConnectionStatus.Connecting, DeviceConnectionPhase.AcquiringCertificate, connectionPhaseDescription); this.deviceConnection.SetDeviceCertificate(await this.GetDeviceCertificate()); certificateAcquired = true; } catch { // This device does not support the root certificate endpoint. this.SendConnectionStatus( DeviceConnectionStatus.Connecting, DeviceConnectionPhase.AcquiringCertificate, "No device certificate available"); } } else { #if WINDOWS_UWP this.deviceConnection.SetDeviceCertificate(new Certificate(rawManualCertificate.AsBuffer())); #else this.deviceConnection.SetDeviceCertificate(new X509Certificate2(rawManualCertificate)); #endif // WINDOWS_UWP certificateAcquired = true; } // Get the device family and operating system information. connectionPhaseDescription = "Requesting operating system information"; this.SendConnectionStatus( DeviceConnectionStatus.Connecting, DeviceConnectionPhase.RequestingOperatingSystemInformation, connectionPhaseDescription); this.deviceConnection.Family = await this.GetDeviceFamily(); this.deviceConnection.OsInfo = await this.GetOperatingSystemInformation(); // Default to using HTTPS if we were successful in acquiring the device's root certificate. bool requiresHttps = certificateAcquired; // HoloLens is the only device that supports the GetIsHttpsRequired method. if (this.deviceConnection.OsInfo.Platform == DevicePortalPlatforms.HoloLens) { // Check to see if HTTPS is required to communicate with this device. connectionPhaseDescription = "Checking secure connection requirements"; this.SendConnectionStatus( DeviceConnectionStatus.Connecting, DeviceConnectionPhase.DeterminingConnectionRequirements, connectionPhaseDescription); requiresHttps = await this.GetIsHttpsRequired(); } // Connect the device to the specified network. if (!string.IsNullOrWhiteSpace(ssid)) { connectionPhaseDescription = string.Format("Connecting to {0} network", ssid); this.SendConnectionStatus( DeviceConnectionStatus.Connecting, DeviceConnectionPhase.ConnectingToTargetNetwork, connectionPhaseDescription); WifiInterfaces wifiInterfaces = await this.GetWifiInterfaces(); // TODO - consider what to do if there is more than one wifi interface on a device await this.ConnectToWifiNetwork(wifiInterfaces.Interfaces[0].Guid, ssid, ssidKey); } // Get the device's IP configuration and update the connection as appropriate. if (updateConnection) { connectionPhaseDescription = "Updating device connection"; this.SendConnectionStatus( DeviceConnectionStatus.Connecting, DeviceConnectionPhase.UpdatingDeviceAddress, connectionPhaseDescription); this.deviceConnection.UpdateConnection(await this.GetIpConfig(), requiresHttps); } this.SendConnectionStatus( DeviceConnectionStatus.Connected, DeviceConnectionPhase.Idle, "Device connection established"); } catch (Exception e) { DevicePortalException dpe = e as DevicePortalException; if (dpe != null) { this.ConnectionHttpStatusCode = dpe.StatusCode; } else { this.ConnectionHttpStatusCode = HttpStatusCode.Conflict; } this.SendConnectionStatus( DeviceConnectionStatus.Failed, DeviceConnectionPhase.Idle, string.Format("Device connection failed: {0}", connectionPhaseDescription)); } }