Last active
August 29, 2015 14:04
-
-
Save elbruno/8d253679235a2d6fe008 to your computer and use it in GitHub Desktop.
El Bruno - Connect to paired BlueTooh Device using PIN
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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