Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
El Bruno - Connect to paired BlueTooh Device using PIN
private static void Main()
{
BluetoothAddress arduinoAdress = null;
_blueToothClient = new BluetoothClient();
var devices = _blueToothClient.DiscoverDevices();
foreach (var device in devices.Where(device => device.DeviceName == "IoT Arduino - Mainframe Bridge"))
{
arduinoAdress = device.DeviceAddress;
Console.WriteLine("Device found, Address:" + arduinoAdress.ToString());
}
_bluetoothDevice = new BluetoothDeviceInfo(arduinoAdress);
if (BluetoothSecurity.PairRequest(_bluetoothDevice.DeviceAddress, "<YOUR PIN GOES HERE>"))
{
Console.WriteLine("Pair request result: :D");
if (_bluetoothDevice.Authenticated)
{
Console.WriteLine("Authenticated result: Cool :D");
_blueToothClient.SetPin("<YOUR PIN GOES HERE>");
_blueToothClient.BeginConnect(_bluetoothDevice.DeviceAddress, BluetoothService.SerialPort, Connect, _bluetoothDevice);
_beginConnect = true;
}
else
{
Console.WriteLine("Authenticated: So sad :(");
}
}
else
{
Console.WriteLine("PairRequest: Sad :(");
}
if (_beginConnect)
{
do
{
ReadFromBtDevice();
Thread.Sleep(1000);
} while (true);
}
Console.ReadLine();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.