Hi all! I introduce myself, my name is Osvaldo, I was recently learning to use Xamarin C # (I only knew how to use Java), I'm doing a hybrid application where from an iPhone or an Android phone can connect via bluetooth to a Raspberry pi zero w, the application has worked but only to a certain extent, first I commented that the application reads LE devices, but not the Raspberry, second the application is only working so far on Android and I do not know why it does not work on IOS, and third I have to extract from the Raspberry the SSID and the wifi password to which it is connected, if you can guide me and help me solve this, I would appreciate a lot !!!
PD: sorry for my English, but I'm still practicing.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections.ObjectModel;
using Plugin.BluetoothLE;
using Xamarin.Forms;
namespace GreenBooth
{
public partial class MainPage : ContentPage
{
IAdapter adapter;
ObservableCollection devices;
IDevice device;
public MainPage()
{
InitializeComponent();
adapter = CrossBleAdapter.Current;
devices = new ObservableCollection<IDevice>();
DevicesList.ItemsSource = devices;
}
/*---------------------------------------------------------------*/
public async void searchDevice(object sender, EventArgs e)
{
devices.Clear(); //limpiamos el contenedor de los dispositivos cada vez que hacemos una busqueda//
if (adapter.Status == AdapterStatus.PoweredOff)
{ //verificamos si el adaptador de bluetooth esta desactivado, tambien puede verificar otros estados//
await DisplayAlert("Atencion!!!", "Bluetooth esta desactivado", "OK");
}
else
{
var scanner = CrossBleAdapter.Current.Scan().Subscribe(scanResult =>
{ //scanResult almacena el dispositivo, el RSSI y el packete de anuncio //
if (!devices.Contains(scanResult.Device))
{
devices.Add(scanResult.Device);
}
});
}
} //----------------Fin busqueda dispositivos------------//
private async void DevicesList_OnItemSelected(object sender, SelectedItemChangedEventArgs e)
{
device = DevicesList.SelectedItem as IDevice;
var result = await DisplayAlert("AVISO", "Desea conectarse a este dispositivo???", "Conectar", "Cancelar");
if (!result)
return;
try
{
}
catch (Exception ex)
{
await DisplayAlert("Error de conexion", ex.Message, "OK");
}
}
private async void Salir(object sender, SelectedItemChangedEventArgs e)
{
System.Diagnostics.Process.GetCurrentProcess().Kill();
}
}
}