public async void MakeConnection()
        {
            try
            {
                AwsMqttConnection awsMqttConnection = new AwsMqttConnection();
                awsMqttConnection.Host      = view1.HostText;
                awsMqttConnection.Region    = view1.RegionText;
                awsMqttConnection.AccessKey = view1.AccessKeyText;
                awsMqttConnection.SecretKey = view1.SecretKeyText;
                awsMqttConnection.ClientId  = new Guid();

                string requestUrl = awsMqttConnection.GetRequesturl();

                var factory = new MqttFactory();
                mqttClient = factory.CreateMqttClient();


                mqttClientOptions = new MqttClientOptionsBuilder()
                                    .WithWebSocketServer(requestUrl)
                                    .Build();

                mqttClient.Connected += MqttClient_Connected;

                await mqttClient.ConnectAsync(mqttClientOptions);
            }
            catch (Exception ex)
            {
                Logger.LogDebug(ex.Message);
            }
        }
Exemplo n.º 2
0
        public void ConnectToAwsIOT()
        {
            try
            {
                AwsMqttConnection awsMqttConnection = new AwsMqttConnection();
                awsMqttConnection.Host      = cloudConnectionConfig.Host;
                awsMqttConnection.Region    = cloudConnectionConfig.Region;
                awsMqttConnection.AccessKey = cloudConnectionConfig.AccessKey;
                awsMqttConnection.SecretKey = cloudConnectionConfig.SecretKey;

                awsMqttConnection.ClientId = new Guid();

                string requestUrl = awsMqttConnection.GetRequesturl();

                var factory = new MqttFactory();
                mqttClient = factory.CreateMqttClient();


                mqttClientOptions = new MqttClientOptionsBuilder()
                                    .WithWebSocketServer(requestUrl)
                                    .Build();



                mqttClient.ConnectAsync(mqttClientOptions).Wait();
                IsConnected = true;
                Logger.LogInfo("Connected successfully .....");
            }
            catch (Exception ex)
            {
                Logger.LogDebug(ex.Message);
            }
        }