Skip to content

Instantly share code, notes, and snippets.

@elbruno
Last active August 29, 2015 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elbruno/8d253679235a2d6fe008 to your computer and use it in GitHub Desktop.
Save elbruno/8d253679235a2d6fe008 to your computer and use it in GitHub Desktop.
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