diff --git a/App/RobobinApp/Models/WifiNetwork.cs b/App/RobobinApp/Models/WifiNetwork.cs index 0e0e8303b1ff372835ec6c23aee6d3e3d326d4df..0a688fbe80fe6270a2343a4b10f655a83918f841 100644 --- a/App/RobobinApp/Models/WifiNetwork.cs +++ b/App/RobobinApp/Models/WifiNetwork.cs @@ -9,6 +9,6 @@ namespace RobobinApp.Models public class WifiNetwork { public string SSID { get; set; } - public string SignalStrength { get; set; } + public double SignalStrength { get; set; } } } diff --git a/App/RobobinApp/RobobinApp.csproj b/App/RobobinApp/RobobinApp.csproj index 47ae3c5d4892cfa6befb028debbc9252c346c625..7d3108fcc44899db531b76b49aaa4607649af7b1 100644 --- a/App/RobobinApp/RobobinApp.csproj +++ b/App/RobobinApp/RobobinApp.csproj @@ -1,6 +1,6 @@ <Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> - <TargetFrameworks>net8.0-ios;net8.0-maccatalyst</TargetFrameworks> + <!-->TargetFrameworks>net8.0-ios;net8.0-maccatalyst</TargetFrameworks--> <TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net8.0-windows10.0.19041.0</TargetFrameworks> <OutputType>Exe</OutputType> <RootNamespace>Robobin</RootNamespace> diff --git a/App/RobobinApp/ViewModels/ConnectionPageViewModel.cs b/App/RobobinApp/ViewModels/ConnectionPageViewModel.cs index 8a728f5bcfe3d9ab4727bb9c8b0b587c09e32df6..f5f6280a21bdb5df4447cd4099adaee26c77a6a8 100644 --- a/App/RobobinApp/ViewModels/ConnectionPageViewModel.cs +++ b/App/RobobinApp/ViewModels/ConnectionPageViewModel.cs @@ -13,6 +13,9 @@ using RobobinApp.Models; using System.Net.NetworkInformation; using System.Collections.Generic; +using Windows.Networking.Connectivity; +using Windows.Devices.WiFi; + namespace RobobinApp.ViewModels { public class ConnectionPageViewModel : BaseViewModel @@ -80,6 +83,7 @@ namespace RobobinApp.ViewModels public ConnectionPageViewModel() { BluetoothDevices = new ObservableCollection<BluetoothDevice>(); + WifiNetworks = new ObservableCollection<WifiNetwork>(); ConnectCommand = new Command(OnConnect); DisconnectCommand = new Command(OnDisconnect); // Initialize disconnect command SendWifiInfoCommand = new Command(OnSendWifiInfo); @@ -92,8 +96,45 @@ namespace RobobinApp.ViewModels Debug.WriteLine("Checking and requesting Bluetooth permissions."); CheckAndRequestBluetoothPermissions(); + ScanForWifiNetworks(); + } + private async void ScanForWifiNetworks() + { + WifiNetworks.Clear(); + Debug.WriteLine("Scanning for Wi-Fi networks..."); + + var wifiAdapter = await GetWifiAdapterAsync(); + if (wifiAdapter == null) + { + Debug.WriteLine("Wi-Fi adapter not found."); + return; + } + + await wifiAdapter.ScanAsync(); + Debug.Write("Scanning for networks"); + var networks = wifiAdapter.NetworkReport.AvailableNetworks; + + foreach (var network in networks) + { + Debug.Write("This network exists" + network.Ssid); + var wifiNetwork = new WifiNetwork + { + SSID = network.Ssid, + SignalStrength = network.NetworkRssiInDecibelMilliwatts + }; + + Device.BeginInvokeOnMainThread(() => WifiNetworks.Add(wifiNetwork)); + Debug.WriteLine($"Found Wi-Fi network: {wifiNetwork.SSID}, Signal Strength: {wifiNetwork.SignalStrength} dBm"); + } + } + + private async Task<WiFiAdapter> GetWifiAdapterAsync() + { + var result = await WiFiAdapter.FindAllAdaptersAsync(); + return result.FirstOrDefault(); // Get the first available Wi-Fi adapter } - private async void OnSendWifiInfo(object obj) + + private async void OnSendWifiInfo(object obj) { if (!_isConnected || _connectedDevice == null) { diff --git a/App/RobobinApp/Views/ConnectionPage.xaml b/App/RobobinApp/Views/ConnectionPage.xaml index d7592573ddb54d6abfa2b6782f5524cbc8081186..61bdfc0e854233dc5bf7b1ea7d08228c2f8075ed 100644 --- a/App/RobobinApp/Views/ConnectionPage.xaml +++ b/App/RobobinApp/Views/ConnectionPage.xaml @@ -90,7 +90,7 @@ VerticalOptions="Start" /> <ListView x:Name="WifiListView" - ItemsSource="{Binding AvailableWifiNetworks}" + ItemsSource="{Binding WifiNetworks}" SelectedItem="{Binding SelectedWifiNetwork}" VerticalOptions="FillAndExpand"> <ListView.ItemTemplate> @@ -100,7 +100,6 @@ </ListView.ItemTemplate> </ListView> - <!-- Section for Password Input --> <StackLayout Padding="10" BackgroundColor="LightGray" HorizontalOptions="FillAndExpand"