Example #1
0
        /// <summary>
        /// Запуск задачи соединения с облаком
        /// </summary>
        /// <param name="connection_string"></param>
        /// <param name="client_id"></param>
        private async Task <bool> Start(MQTTClient client)
        {
            return(await Task.Run(() =>
            {
                try
                {
                    var configuration = new MqttConfiguration
                    {
                        //BufferSize = 128 * 1024,
                        Port = client.Port
                               //KeepAliveSecs = 10,
                               //WaitTimeoutSecs = 12,
                               //MaximumQualityOfService = MqttQualityOfService.AtMostOnce
                               //AllowWildcardsInTopicFilters = true
                    };

                    //System.Net.Sockets.Socket.
                    CloudConnectionResult.Message = "В ожидании соединения";
                    _client = MqttClient.CreateAsync(client.Server, configuration).Result;
                    _client.Disconnected += _client_Disconnected;
                    var sessionState = _client.ConnectAsync(new MqttClientCredentials(clientId: client.ClientId, userName: client.UserName, password: client.Password), cleanSession: false).Result;
                    CloudConnectionResult.Message = "Соединение установлено";
                    return true;
                }
                catch (System.Exception ex)
                {
                    CloudConnectionResult.Message = ex.Message;
                    Log.Debug(MQTT_TAG, ex.Message);
                    Toast.MakeText(_context, ex.Message, ToastLength.Long);
                    return false;
                }
            }));
        }
Example #2
0
        private async void StartAsync(MQTTClient client)
        {
            bool result = await Start(client);

            CreateAlertResult();
        }
Example #3
0
 public MQTTService(MQTTClient client, Context context)
 {
     this._context = context;
     StartAsync(client);
 }