32feet
32feet copied to clipboard
Subscribing to sender notifications in iOS dotnet maui
Hello,
I am trying to get Geolocation data from a GNSS receiver that uses BT Classic. I am able to successfully connect to the device but I am not sure how to listen for update notifications from the receiver.
Any help would be greatly appreciated!
Thanks using System.Diagnostics; using ExternalAccessory; using InTheHand.Bluetooth; using InTheHand.Net.Bluetooth; using InTheHand.Net.Sockets;
namespace EOSConnect;
public partial class MainPage : ContentPage { int count = 0;
Stream stream = null;
public MainPage()
{
InitializeComponent();
}
private async void OnCounterClicked(object sender, EventArgs e)
{
BluetoothClient client = new BluetoothClient();
BluetoothDeviceInfo device = null;
device = client.PairedDevices.FirstOrDefault();
if (device != null)
{
bool paired = BluetoothSecurity.PairRequest(device.DeviceAddress, "0000");
await Task.Delay(2000);
client.Connect(device.DeviceAddress, BluetoothService.SerialPort);
if (client.Connected)
{
//i tried this method but the stream has a size of 0.
stream = client.GetStream();
var ss = stream.CanRead;
StreamReader sr = new StreamReader(stream, System.Text.Encoding.ASCII);
char[] buffer = new char[10000];
await sr.ReadAsync(buffer, 0, (int)stream.Length);
sr.Close();
}
}
}
}
A classic GPS device sends back a constant stream of NMEA data (usually one reading per second). These will be separated with a linebreak character. You can use a loop in a worker thread to keep reading the data using StreamReader.ReadLine for example. Then you'll need to parse the raw data.