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
public class WifiNetwork
{
public string SSID { get; set; }
public string SignalStrength { get; set; }
public double SignalStrength { get; set; }
}
}
<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>
......
......@@ -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)
{
......
......@@ -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"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment