Skip to content
Snippets Groups Projects
Commit e0ff20bd authored by Paul-Winpenny's avatar Paul-Winpenny
Browse files

Wifi List shows up, need to bind the selected device to SSID in viewmodel

parent 4efb23b3
No related branches found
No related tags found
1 merge request!1App now has a basic structure and BLE support
...@@ -9,6 +9,6 @@ namespace RobobinApp.Models ...@@ -9,6 +9,6 @@ namespace RobobinApp.Models
public class WifiNetwork public class WifiNetwork
{ {
public string SSID { get; set; } public string SSID { get; set; }
public string SignalStrength { get; set; } public double SignalStrength { get; set; }
} }
} }
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <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> <TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net8.0-windows10.0.19041.0</TargetFrameworks>
<OutputType>Exe</OutputType> <OutputType>Exe</OutputType>
<RootNamespace>Robobin</RootNamespace> <RootNamespace>Robobin</RootNamespace>
......
...@@ -13,6 +13,9 @@ using RobobinApp.Models; ...@@ -13,6 +13,9 @@ using RobobinApp.Models;
using System.Net.NetworkInformation; using System.Net.NetworkInformation;
using System.Collections.Generic; using System.Collections.Generic;
using Windows.Networking.Connectivity;
using Windows.Devices.WiFi;
namespace RobobinApp.ViewModels namespace RobobinApp.ViewModels
{ {
public class ConnectionPageViewModel : BaseViewModel public class ConnectionPageViewModel : BaseViewModel
...@@ -80,6 +83,7 @@ namespace RobobinApp.ViewModels ...@@ -80,6 +83,7 @@ namespace RobobinApp.ViewModels
public ConnectionPageViewModel() public ConnectionPageViewModel()
{ {
BluetoothDevices = new ObservableCollection<BluetoothDevice>(); BluetoothDevices = new ObservableCollection<BluetoothDevice>();
WifiNetworks = new ObservableCollection<WifiNetwork>();
ConnectCommand = new Command(OnConnect); ConnectCommand = new Command(OnConnect);
DisconnectCommand = new Command(OnDisconnect); // Initialize disconnect command DisconnectCommand = new Command(OnDisconnect); // Initialize disconnect command
SendWifiInfoCommand = new Command(OnSendWifiInfo); SendWifiInfoCommand = new Command(OnSendWifiInfo);
...@@ -92,8 +96,45 @@ namespace RobobinApp.ViewModels ...@@ -92,8 +96,45 @@ namespace RobobinApp.ViewModels
Debug.WriteLine("Checking and requesting Bluetooth permissions."); Debug.WriteLine("Checking and requesting Bluetooth permissions.");
CheckAndRequestBluetoothPermissions(); 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) if (!_isConnected || _connectedDevice == null)
{ {
......
...@@ -90,7 +90,7 @@ ...@@ -90,7 +90,7 @@
VerticalOptions="Start" /> VerticalOptions="Start" />
<ListView x:Name="WifiListView" <ListView x:Name="WifiListView"
ItemsSource="{Binding AvailableWifiNetworks}" ItemsSource="{Binding WifiNetworks}"
SelectedItem="{Binding SelectedWifiNetwork}" SelectedItem="{Binding SelectedWifiNetwork}"
VerticalOptions="FillAndExpand"> VerticalOptions="FillAndExpand">
<ListView.ItemTemplate> <ListView.ItemTemplate>
...@@ -100,7 +100,6 @@ ...@@ -100,7 +100,6 @@
</ListView.ItemTemplate> </ListView.ItemTemplate>
</ListView> </ListView>
<!-- Section for Password Input -->
<StackLayout Padding="10" <StackLayout Padding="10"
BackgroundColor="LightGray" BackgroundColor="LightGray"
HorizontalOptions="FillAndExpand" HorizontalOptions="FillAndExpand"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment