-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added capability to connect to wifi network
Very basic
- Loading branch information
Showing
17 changed files
with
322 additions
and
29 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,30 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
|
||
<Package | ||
xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10" | ||
xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest" | ||
xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10" | ||
IgnorableNamespaces="uap mp"> | ||
|
||
<Identity | ||
Name="655322c3-787d-4e4a-947e-cd2a5db6577a" | ||
Publisher="CN=chris" | ||
Version="1.0.0.0" /> | ||
|
||
<mp:PhoneIdentity PhoneProductId="655322c3-787d-4e4a-947e-cd2a5db6577a" PhonePublisherId="00000000-0000-0000-0000-000000000000"/> | ||
|
||
<Package xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10" xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest" xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10" IgnorableNamespaces="uap mp"> | ||
<Identity Name="655322c3-787d-4e4a-947e-cd2a5db6577a" Publisher="CN=chris" Version="1.1.1.0" /> | ||
<mp:PhoneIdentity PhoneProductId="655322c3-787d-4e4a-947e-cd2a5db6577a" PhonePublisherId="00000000-0000-0000-0000-000000000000" /> | ||
<Properties> | ||
<DisplayName>IoTBrowser</DisplayName> | ||
<PublisherDisplayName>chris</PublisherDisplayName> | ||
<Logo>Assets\StoreLogo.png</Logo> | ||
</Properties> | ||
|
||
<Dependencies> | ||
<TargetDeviceFamily Name="Windows.Universal" MinVersion="10.0.0.0" MaxVersionTested="10.0.0.0" /> | ||
</Dependencies> | ||
|
||
<Resources> | ||
<Resource Language="x-generate"/> | ||
<Resource Language="x-generate" /> | ||
</Resources> | ||
|
||
<Applications> | ||
<Application Id="App" | ||
Executable="$targetnametoken$.exe" | ||
EntryPoint="IoTBrowser.App"> | ||
<uap:VisualElements | ||
DisplayName="IoTBrowser" | ||
Square150x150Logo="Assets\Square150x150Logo.png" | ||
Square44x44Logo="Assets\Square44x44Logo.png" | ||
Description="IoTBrowser" | ||
BackgroundColor="transparent"> | ||
<uap:DefaultTile Wide310x150Logo="Assets\Wide310x150Logo.png"/> | ||
<Application Id="App" Executable="$targetnametoken$.exe" EntryPoint="IoTBrowser.App"> | ||
<uap:VisualElements DisplayName="IoTBrowser" Square150x150Logo="Assets\Square150x150Logo.png" Square44x44Logo="Assets\Square44x44Logo.png" Description="IoTBrowser" BackgroundColor="transparent"> | ||
<uap:DefaultTile Wide310x150Logo="Assets\Wide310x150Logo.png"> | ||
</uap:DefaultTile> | ||
<uap:SplashScreen Image="Assets\SplashScreen.png" /> | ||
</uap:VisualElements> | ||
</Application> | ||
</Applications> | ||
|
||
<Capabilities> | ||
<Capability Name="internetClient" /> | ||
<DeviceCapability Name="location" /> | ||
<DeviceCapability Name="wifiControl" /> | ||
</Capabilities> | ||
</Package> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<Page | ||
x:Class="IoTBrowser.WifiPage" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:local="using:IoTBrowser" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
mc:Ignorable="d"> | ||
|
||
|
||
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> | ||
<Grid.RowDefinitions> | ||
<RowDefinition Height="60"/> | ||
<RowDefinition Height="60"/> | ||
<RowDefinition Height="*"/> | ||
<RowDefinition Height="60"/> | ||
</Grid.RowDefinitions> | ||
|
||
<TextBlock FontSize="36" Grid.RowSpan="2" >WiFi Scanner</TextBlock> | ||
|
||
<ScrollViewer Grid.Row="1" HorizontalAlignment="Stretch" HorizontalScrollBarVisibility ="Auto" VerticalScrollBarVisibility="Auto"> | ||
<Grid > | ||
<Grid.ColumnDefinitions> | ||
<ColumnDefinition Width="150"></ColumnDefinition> | ||
<ColumnDefinition></ColumnDefinition> | ||
</Grid.ColumnDefinitions> | ||
<Button Name="btnScan" Click="btnScan_Click" Grid.Column="0">Scan For Networks</Button> | ||
<Button Name="btnBrowser" Click="btnBrowser_Click" Grid.Column="1">Back To Browser</Button> | ||
</Grid> | ||
</ScrollViewer> | ||
|
||
|
||
<ListView x:Name="report_lv" Grid.Row="2" ItemClick="report_lv_ItemClick" IsItemClickEnabled="True"> | ||
<ListView.ItemTemplate> | ||
<DataTemplate x:DataType="x:String"> | ||
<Grid> | ||
<Grid.ColumnDefinitions> | ||
<ColumnDefinition Width="54"/> | ||
<ColumnDefinition/> | ||
</Grid.ColumnDefinitions> | ||
<Image Source="{Binding Icon}" Width="44" Height="44" HorizontalAlignment="Left"/> | ||
<TextBlock Text="{Binding SSID}" FontSize="36" Grid.Column="1"/> | ||
</Grid> | ||
</DataTemplate> | ||
</ListView.ItemTemplate> | ||
</ListView> | ||
|
||
|
||
|
||
<ScrollViewer Grid.Row="3" HorizontalAlignment="Stretch" HorizontalScrollBarVisibility ="Auto" VerticalScrollBarVisibility="Auto"> | ||
<Grid > | ||
<Grid.ColumnDefinitions> | ||
<ColumnDefinition Width="*"></ColumnDefinition> | ||
<ColumnDefinition Width="100"></ColumnDefinition> | ||
</Grid.ColumnDefinitions> | ||
<TextBox Grid.Column="0" Name="txtPassword" HorizontalAlignment="Stretch" FontSize="24" VerticalAlignment="Center" VerticalContentAlignment="Center" Text="asd"></TextBox> | ||
<Button Grid.Column="1" Name="btnConnect" Click="btnConnect_Click" HorizontalAlignment="Right" VerticalAlignment="Center" Height="40" Width="95">Connect</Button> | ||
</Grid> | ||
</ScrollViewer> | ||
</Grid> | ||
</Page> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,164 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Runtime.InteropServices.WindowsRuntime; | ||
using Windows.Foundation; | ||
using Windows.Foundation.Collections; | ||
using Windows.UI.Xaml; | ||
using Windows.UI.Xaml.Controls; | ||
using Windows.UI.Xaml.Controls.Primitives; | ||
using Windows.UI.Xaml.Data; | ||
using Windows.UI.Xaml.Input; | ||
using Windows.UI.Xaml.Media; | ||
using Windows.UI.Xaml.Navigation; | ||
using Windows.Devices.WiFi; | ||
using System.Collections.ObjectModel; | ||
using Windows.UI.Popups; | ||
using System.Threading.Tasks; | ||
using System.Text; | ||
using Windows.Networking.Connectivity; | ||
using Windows.Security.Credentials; | ||
using Windows.Devices.Enumeration; | ||
|
||
// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238 | ||
|
||
namespace IoTBrowser | ||
{ | ||
/// <summary> | ||
/// An empty page that can be used on its own or navigated to within a Frame. | ||
/// </summary> | ||
public sealed partial class WifiPage : Page | ||
{ | ||
private WiFiScanner _wifiScanner; | ||
private bool _scannerInitialized = false; | ||
private string _selectedSSID = ""; | ||
WiFiNetworkReport _report; | ||
|
||
public WifiPage() | ||
{ | ||
this.InitializeComponent(); | ||
|
||
this._wifiScanner = new WiFiScanner(); | ||
} | ||
|
||
private async void Page_Loaded(object sender, RoutedEventArgs e) | ||
{ | ||
await InitializeScanner(); | ||
} | ||
|
||
private async Task InitializeScanner() | ||
{ | ||
if (!_scannerInitialized) | ||
{ | ||
await this._wifiScanner.InitializeScanner(); | ||
_scannerInitialized = true; | ||
} | ||
} | ||
|
||
private async void btnScan_Click(object sender, RoutedEventArgs e) | ||
{ | ||
await InitializeScanner(); | ||
this.btnScan.IsEnabled = false; | ||
|
||
try | ||
{ | ||
await RunWifiScan(); | ||
} | ||
catch (Exception ex) | ||
{ | ||
MessageDialog md = new MessageDialog(ex.Message); | ||
await md.ShowAsync(); | ||
} | ||
|
||
this.btnScan.IsEnabled = true; | ||
} | ||
|
||
|
||
private async Task RunWifiScan() | ||
{ | ||
await this._wifiScanner.ScanForNetworks(); | ||
|
||
_report = this._wifiScanner.WiFiAdapter.NetworkReport; | ||
|
||
ObservableCollection<WifiList> ocwl = new ObservableCollection<WifiList>(); | ||
|
||
foreach (var availableNetwork in _report.AvailableNetworks) | ||
{ | ||
|
||
if (availableNetwork.Ssid.Length > 1) | ||
{ | ||
string icon = ""; | ||
if(availableNetwork.SecuritySettings.NetworkEncryptionType.ToString() == "None") { icon = "open_"; } | ||
else { icon = "secure_"; } | ||
icon = icon + availableNetwork.SignalBars + "bar.png"; | ||
|
||
WifiList wl = new WifiList { Icon = "Assets/"+icon, SSID = availableNetwork.Ssid }; | ||
|
||
ocwl.Add(wl); | ||
} | ||
} | ||
|
||
report_lv.ItemsSource = ocwl; | ||
|
||
|
||
} | ||
|
||
|
||
private async Task ShowMessage(string message) | ||
{ | ||
var dialog = new MessageDialog(message); | ||
await dialog.ShowAsync(); | ||
} | ||
|
||
private void btnBrowser_Click(object sender, RoutedEventArgs e) | ||
{ | ||
this.Frame.Navigate(typeof(MainPage)); | ||
} | ||
|
||
private async void btnConnect_Click(object sender, RoutedEventArgs e) | ||
{ | ||
|
||
var access = await WiFiAdapter.RequestAccessAsync(); | ||
var wifiAdapterResults = await DeviceInformation.FindAllAsync(WiFiAdapter.GetDeviceSelector()); | ||
WiFiAdapter wa = await WiFiAdapter.FromIdAsync(wifiAdapterResults[0].Id); | ||
|
||
WiFiReconnectionKind reconnectionKind = WiFiReconnectionKind.Automatic; | ||
WiFiConnectionResult result; | ||
|
||
foreach (var availableNetwork in _report.AvailableNetworks) | ||
{ | ||
if (availableNetwork.Ssid == _selectedSSID) | ||
{ | ||
if (txtPassword.Text.Length > 1) | ||
{ | ||
var credential = new PasswordCredential(); | ||
credential.Password = txtPassword.Text; | ||
result = await wa.ConnectAsync(availableNetwork, reconnectionKind, credential); | ||
} | ||
else | ||
{ | ||
result = await wa.ConnectAsync(availableNetwork, reconnectionKind); | ||
} | ||
} | ||
} | ||
|
||
|
||
|
||
} | ||
|
||
private void report_lv_ItemClick(object sender, ItemClickEventArgs e) | ||
{ | ||
|
||
WifiList item = (WifiList)e.ClickedItem; | ||
//txtPassword.Text = item.SSID; | ||
_selectedSSID = item.SSID; | ||
} | ||
} | ||
} | ||
|
||
public class WifiList | ||
{ | ||
public string SSID { get; set; } | ||
public string Icon { get; set; } | ||
} |
Oops, something went wrong.