Пример #1
0
        public MainPage()
        {
            this.DataContext = new MainPageViewModel();
            mqttService      = new MqttService();


            devicePicker = new DevicePicker();
            this.devicePicker.DeviceSelected += async(devicePicker, args) =>
            {
                var device = args.SelectedDevice;
                devicePicker.Hide();

                await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() =>
                {
                    try
                    {
                        await mqttService.StartAsync();


                        await PairDeviceIfNecessary(device);

                        await ConnectIGrill(device);
                        Settings.SelectedDeviceId = device.Id;
                    } catch (Exception ex)
                    {
                    }
                });
            };
            devicePicker.Filter.SupportedDeviceSelectors.Add(BluetoothLEDevice.GetDeviceSelectorFromPairingState(false));
            devicePicker.Filter.SupportedDeviceSelectors.Add(BluetoothLEDevice.GetDeviceSelectorFromPairingState(true));

            this.InitializeComponent();
        }