nuimo-windows
nuimo-windows copied to clipboard
Automatic Pairing?
Hey there.
About a month ago, I slowly started making the steps for developing my own SDK, until I heard you were already making one. The first thing I did, was make sure I could connect to the Nuimo programmatically, without the user having to pair it first. And so I did. I'll post some snippets of the code here, so you can implement it into the SDK if you want. If not, I'll just keep that part in my own application. It could definitely use some polish, but it was just a proof of concept to make sure I could connect it programmatically.
static void Main(string[] arg)
{
var aqsFilter = "System.Devices.Aep.ProtocolId:=\"{bb7bb05e-5972-42b5-94fc-76eaa7084d49}\"";
var deviceWatcher = DeviceInformation.CreateWatcher(aqsFilter, new[] {"System.Devices.Aep.IsPaired"},
DeviceInformationKind.AssociationEndpoint);
deviceWatcher.Added += DeviceWatcher_Added;
deviceWatcher.Updated += DeviceWatcher_Updated;
deviceWatcher.Start();
Console.ReadLine();
});
private static void DeviceWatcher_Updated(DeviceWatcher sender, DeviceInformationUpdate args)
{
}
private static async void DeviceWatcher_Added(DeviceWatcher sender, DeviceInformation args)
{
if (args.Name != "Nuimo")
return;
sender.Stop();
Console.WriteLine(args.Name);
foreach (var keyValuePair in args.Properties)
{
Console.WriteLine($"{keyValuePair.Key}: {keyValuePair.Value}");
}
if (!args.Pairing.IsPaired)
{
DevicePairingKinds ceremoniesSelected = DevicePairingKinds.ConfirmOnly | DevicePairingKinds.DisplayPin | DevicePairingKinds.ProvidePin | DevicePairingKinds.ConfirmPinMatch;
DevicePairingProtectionLevel protectionLevel = DevicePairingProtectionLevel.Default;
// Specify custom pairing with all ceremony types and protection level EncryptionAndAuthentication
DeviceInformationCustomPairing customPairing = args.Pairing.Custom;
customPairing.PairingRequested += PairingRequestedHandler;
var result = await customPairing.PairAsync(ceremoniesSelected, protectionLevel);
customPairing.PairingRequested -= PairingRequestedHandler;
if (result.Status == DevicePairingResultStatus.Paired)
{
Console.WriteLine("Successfully paired! :D");
}
else
{
Console.WriteLine("Pairing Failed " + result.Status);
return;
}
}
}
private static void PairingRequestedHandler(DeviceInformationCustomPairing sender, DevicePairingRequestedEventArgs args)
{
args.Accept();
}
@Inrego cool! it has some similarities (using DeviceWatcher) with my suggestion (see https://github.com/getsenic/nuimo-windows/issues/5)
Thanks @Inrego for your example snippet – as soon as we have time we'll look into it.
@Inrego @larsblumberg according to https://blogs.windows.com/buildingapps/2017/01/13/new-bluetooth-features-in-creators-update-gatt-server-bluetooth-le/, pairing won't be needed anymore starting from the Windows 10 Creators Update (and said to be available as an insider build now, but I can't download the insider sdk).
Good news!