Ejemplo n.º 1
0
        private async void Connect(object sender, RoutedEventArgs e)
        {
            var options = new MqttClientOptions
            {
                Server   = Server.Text,
                UserName = User.Text,
                Password = Password.Text,
                ClientId = ClientId.Text
            };

            options.TlsOptions.UseTls = UseTls.IsChecked == true;

            try
            {
                if (_mqttClient != null)
                {
                    await _mqttClient.DisconnectAsync();
                }

                var factory = new MqttClientFactory();
                _mqttClient = factory.CreateMqttClient(options);
                await _mqttClient.ConnectAsync();
            }
            catch (Exception exception)
            {
                Trace.Text += exception + Environment.NewLine;
            }
        }