Beispiel #1
0
        public async Task HandleConnectedAsync(MqttClientConnectedEventArgs eventArgs)
        {
            System.Console.WriteLine("Agent-Broker connected");
            await hubContext.Clients.All.AgentConnectionStatus(true);

            await mqttClient.SubscribeAsync("#");
        }
Beispiel #2
0
 private void MqttClient_Connected(object sender, MqttClientConnectedEventArgs e)
 {
     if (OnMqttConnectNotify != null)
     {
         OnMqttConnectNotify(sender, new MqttConnectNotifyEventArgs(true));
     }
 }
Beispiel #3
0
 private void connected(MqttClientConnectedEventArgs obj)
 {
     Debug.WriteLine("MQTT Conectado");
     EstadoCloud = true;
     subtopic();
     UpdateGUI();
 }
Beispiel #4
0
 public Task HandleConnectedAsync(MqttClientConnectedEventArgs eventArgs)
 {
     return(Task.Run(() =>
     {
         Console.WriteLine("连接成功!");
     }));
 }
Beispiel #5
0
            /// <summary>
            /// client 成功连接到 server
            /// </summary>
            /// <param name="e"></param>
            /// <returns></returns>
            private async Task Connected(MqttClientConnectedEventArgs e)
            {
                try
                {
                    List <MqttTopicFilter> listTopic = new List <MqttTopicFilter>();
                    if (listTopic.Count() <= 0)
                    {
                        foreach (string topic in topicsSubs)
                        {
                            var topicFilterBulder = new MqttTopicFilterBuilder().WithTopic(topic).Build();
                            listTopic.Add(topicFilterBulder);
                            Console.WriteLine("Connected >>Subscribe " + topic);
                        }
                    }

                    // 订阅主题
                    await mqttClient.SubscribeAsync(listTopic.ToArray());

                    Console.WriteLine("Connected >>Subscribe Success");
                }
                catch (Exception exp)
                {
                    Console.WriteLine(exp.Message);
                }

                ClientConnectedEvent?.Invoke();
            }
 private void OnConnected(object sender, MqttClientConnectedEventArgs args)
 {
     if (Connected != null)
     {
         _dispatcher.Post(() => Connected.Invoke(_id, sender, args));
     }
 }
Beispiel #7
0
 private async Task HandleConnection(MqttClientConnectedEventArgs arg)
 {
     if (ConnectionStateChanged != null)
     {
         await ConnectionStateChanged.Invoke();
     }
 }
        private async Task OnConnected(MqttClientConnectedEventArgs e)
        {
            _logger.LogInformation($"Connected to {_nexusUrl}.");

            // Subscribe to all stalk related event topics.
            await MqttClient.SubscribeAsync(
                // Keyboard
                new MqttTopicFilterBuilder().WithTopic(string.Format(StalkTopic.SendKey, _clientId)).Build(),
                new MqttTopicFilterBuilder().WithTopic(string.Format(StalkTopic.SendKeys, _clientId)).Build(),
                new MqttTopicFilterBuilder().WithTopic(string.Format(StalkTopic.SendKeysRaw, _clientId)).Build(),
                new MqttTopicFilterBuilder().WithTopic(string.Format(StalkTopic.SendKeysReset, _clientId)).Build(),
                new MqttTopicFilterBuilder().WithTopic(string.Format(StalkTopic.KeypressDuration, _clientId)).Build(),

                // Mouse
                new MqttTopicFilterBuilder().WithTopic(string.Format(StalkTopic.SendMouseClick, _clientId)).Build(),
                new MqttTopicFilterBuilder().WithTopic(string.Format(StalkTopic.SendMouseActions, _clientId)).Build(),
                new MqttTopicFilterBuilder().WithTopic(string.Format(StalkTopic.SendMouseRaw, _clientId)).Build(),
                new MqttTopicFilterBuilder().WithTopic(string.Format(StalkTopic.SendMouseReset, _clientId)).Build(),
                new MqttTopicFilterBuilder().WithTopic(string.Format(StalkTopic.ClickDuration, _clientId)).Build(),

                // Joystick
                new MqttTopicFilterBuilder().WithTopic(string.Format(StalkTopic.SendJoystickActions, _clientId)).Build(),
                new MqttTopicFilterBuilder().WithTopic(string.Format(StalkTopic.SendJoystickRaw, _clientId)).Build(),

                // Led Matrix
                new MqttTopicFilterBuilder().WithTopic(string.Format(StalkTopic.SendLedMatrix, _clientId)).Build()
                );

            // Report that we've connected.
            await Publish(StalkTopic.Status_BeholderStalk, "Connected", true);
        }
Beispiel #9
0
        private void MqttClient_Connected(object sender, MqttClientConnectedEventArgs e)
        {
            var topics = TopicEvent?.Invoke();

            SubscribeAsync(topics);
            ConnectEvent?.Invoke(true, null);
        }
 private Task HandleConnected(MqttClientConnectedEventArgs arg)
 {
     Logger.LogInformation("Client connected: {@Reason}", arg.AuthenticateResult);
     _jitterBackoff.Clear();
     OnConnected(arg.AuthenticateResult);
     return(Task.CompletedTask);
 }
Beispiel #11
0
 /// <summary>
 /// MQTT Client connection event handler
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void Client_Connected(object sender, MqttClientConnectedEventArgs e)
 {
     isConnected = client.IsConnected;
     Console.WriteLine($"MQTT Client connected to {Broker}");
     Console.WriteLine($"MQTT Client subscribing to {Topic}");
     client.SubscribeAsync(new TopicFilterBuilder().WithTopic(Topic).Build());
 }
Beispiel #12
0
 public async Task HandleConnectedAsync(MqttClientConnectedEventArgs eventArgs)
 {
     Log.Information("Connected with broker service");
     await this.client.SubscribeAsync(
         this.config.GetSection("MqttClientConfig:MqttSubscribedTopic").Get <string>()
         );
 }
Beispiel #13
0
        private async void Client_Connected(object sender, MqttClientConnectedEventArgs e)
        {
            SetStatus(Client.IsConnected ? "Connected" : "Connection failed");
            try
            {
                if (Client.IsConnected)
                {
                    ClientDispatcher.Invoke(() => SendNewData());

                    //List<TopicFilter> filters = new List<TopicFilter>();
                    IList<MqttSubscribeResult> result;
                    for (int i = 0; i < DataPointCount; i++)
                    {
                        List<TopicFilter> filters = new List<TopicFilter>();
                        filters.Add(new TopicFilter(PointName(i), QualityOfService));
#if HAVE_SYNC
                        if (IsSync)
                            result = Client.Subscribe(filters);
                        else
#endif
                            await Client.SubscribeAsync(filters);
                    }
                    Paused = false;
                }
            }
            catch (Exception ex)
            {
                SetStatus(ex.Message);
            }
        }
Beispiel #14
0
        public async Task HandleConnectedAsync(MqttClientConnectedEventArgs eventArgs)
        {
            Tools.guardarLog("MQTT Server Connected");

            // Subscribe Topics
            //await mqttClient.SubscribeAsync("ovms/jchm/KonaEV/metric/v/#");
            await mqttClient.SubscribeAsync("abrp/status");

            await mqttClient.SubscribeAsync("ovms/jchm/KonaEV/metric/v/e/on");

            await mqttClient.SubscribeAsync("ovms/jchm/KonaEV/metric/v/c/charging");

            await mqttClient.SubscribeAsync("ovms/jchm/KonaEV/metric/v/p/latitude");

            await mqttClient.SubscribeAsync("ovms/jchm/KonaEV/metric/v/p/longitude");

            await mqttClient.SubscribeAsync("ovms/jchm/KonaEV/metric/v/p/altitude");

            await mqttClient.SubscribeAsync("ovms/jchm/KonaEV/metric/v/b/soc");

            await mqttClient.SubscribeAsync("ovms/jchm/KonaEV/metric/v/b/soh");

            await mqttClient.SubscribeAsync("ovms/jchm/KonaEV/metric/v/p/speed");

            await mqttClient.SubscribeAsync("ovms/jchm/KonaEV/metric/v/e/temp");

            await mqttClient.SubscribeAsync("ovms/jchm/KonaEV/metric/v/b/temp");

            await mqttClient.SubscribeAsync("ovms/jchm/KonaEV/metric/v/b/voltage");

            await mqttClient.SubscribeAsync("ovms/jchm/KonaEV/metric/v/b/current");

            await mqttClient.SubscribeAsync("ovms/jchm/KonaEV/metric/v/b/power");
        }
Beispiel #15
0
        private async void MqttServer_ClientConnected(object sender, MqttClientConnectedEventArgs e)
        {
            Console.WriteLine("Broker: ClientConnected");

            // do not create clientmanager for connecting fakeClient
            if (e.ClientId.EndsWith("_fake"))
            {
                return;
            }

            if (clientManagers.ContainsKey(e.ClientId))
            {
                Console.WriteLine("Client" + e.ClientId + " is reconnecting!");
                //clientManagers.Remove(e.ClientId);
                //throw new Exception("ClientId already exists!");
            }
            else
            {
                Console.WriteLine("Broker: Creating new ClientManager");
                clientManagers[e.ClientId] = new MQTT_Proxy.ClientManager(e.ClientId, proxyConfig);
                Console.WriteLine("Broker: ClientManager created");
                Console.WriteLine("Broker: Connecting ClientManager");
                await clientManagers[e.ClientId].Connect();
                Console.WriteLine("Broker: ClientManager connected");
            }
        }
Beispiel #16
0
        public async Task HandleConnectedAsync(MqttClientConnectedEventArgs e)
        {
            this.logger.LogInformation("connected to mqtt server");

            // TODO subscribe to topics
            await this.mqttClient.SubscribeAsync("cmnd/chaosSwitch1/power");
        }
Beispiel #17
0
        /// <summary>
        /// The handler is called on the mqtt client has successfully connected
        /// </summary>
        /// <param name="eventArgs"></param>
        /// <returns></returns>
        public async Task HandleConnectedAsync(MqttClientConnectedEventArgs eventArgs)
        {
            _logger.Debug($"{nameof(HandleConnectedAsync)} - connected with server");

            try
            {
                await _client.SubscribeAsync(DialogIntentMessageQueueName);

                if (OnFrameReceivedHandler != null)
                {
                    await _client.SubscribeAsync(AudioFrameMessageQueueName);
                }
                await _client.SubscribeAsync(DialogSessionStartedMessageQueueName);

                await _client.SubscribeAsync(DialogSessionQueuedMessageQueueName);

                await _client.SubscribeAsync(DialogSessionEndedMessageQueueName);

                await _client.SubscribeAsync(DialogIntentNotRecognizedMessageQueueName);

                _logger.Debug($"{nameof(HandleConnectedAsync)} - successfully subscribed.");
            }
            catch (Exception ex)
            {
                _logger.Error(ex, $"{nameof(HandleConnectedAsync)} - failed to subscribe!");
                throw;
            }
        }
Beispiel #18
0
 private void MqttClient_Connected(object sender, MqttClientConnectedEventArgs e)
 {
     Invoke((new Action(() =>
     {
         Status_Label.Text = $"状态:已连接!";
     })));
 }
        private async void UseConnectedHandler(IMqttClient mqttClient, string topic, MqttClientConnectedEventArgs conn)
        {
            Console.WriteLine("MQTT CLIENT - CONNECTED TO MQTT BROKER");

            // subscribe to tenant and landscape specific topic
            mqttClient.SubscribeAsync(topic, MQTTnet.Protocol.MqttQualityOfServiceLevel.AtLeastOnce);

            // brodcast my peer info
            BroadcastMyPeerInfo("INSTANCE_CONNECTED");

            // send topic queue messages (topic is specific to tenantId and mqttClient already
            if (MQTTSendQueue.MessagesToSend.Count > 0)
            {
                lock (MQTTSendQueue.MessagesToSend)
                {
                    // ignore if it changes
                    try
                    {
                        var qMessages = MQTTSendQueue.MessagesToSend.FindAll(qm => qm.Topic.CompareTo(topic) == 0).ToList();

                        foreach (var qMessage in MQTTSendQueue.MessagesToSend)
                        {
                            if (mqttClient.IsConnected)
                            {
                                mqttClient.PublishAsync(topic, qMessage.QueuedMessage, qMessage.QoS);
                                MQTTSendQueue.MessagesToSend.Remove(qMessage);
                                InstanceHealthService.Health.MQTTMessagesSent += 1;
                            }
                        }
                    }
                    catch { }
                }
            }
        }
Beispiel #20
0
 private void ClientConnectedHandler(MqttClientConnectedEventArgs arg)
 {
     Console.WriteLine("Connected successfully with MQTT Brokers.");
     _ = SubscribeAsync("/iot/zolertia/reply", 1);
     _ = SubscribeAsync("/iot/sensor/reply", 1);
     _ = SubscribeAsync("/iot/zolertia/data", 1);
 }
Beispiel #21
0
        async void Connected(object sender, MqttClientConnectedEventArgs e)
        {
            logger.Debug("Mqqtclient Connected to server");

            // Subscribe to a topic
            await mqttClient.SubscribeAsync(new TopicFilterBuilder().WithTopic(MQTTRoot + "/#").Build());
        }
Beispiel #22
0
        private async Task OnMqttConnectedAsync(MqttClientConnectedEventArgs obj)
        {
            if (MqttClient.IsConnected)
            {
                ///上位机默认订阅UPLOAD
                await Subscribe(new List <string>
                {
                    "uploadhex/358826100269329",
                    //"uploadhex/861410047695456",
                    //"uploadhex/861410047695456",
                    "uploadstr/358826100269329",
                    "cmdstr/light/#",
                    "cmdhex/light/#",
                });

                ///上位机默认订阅UPLOAD
                //await Subscribe(new List<string>
                //{
                //    "uploadhex/861410047743793",
                //    "light/861410047743793",
                //    "uploadstr/#",
                //    //"cmdstr/#",
                //    "cmdstr/light/861410047743793",
                //    "cmdhex/#",
                //});
            }
            else
            {
                notification.Show("连接失败...");
            }
        }
Beispiel #23
0
 private void OnConnected(MqttClientConnectedEventArgs args)
 {
     _logger.LogInformation($"MQTT客户端: {_mqttClientOptions.ClientId} 连接成功");
     Console.WriteLine($"MQTT客户端: {_mqttClientOptions.ClientId} 连接成功");
     //    重置重试链接次数
     _currentRetryConnectedNum = 1;
 }
Beispiel #24
0
 private async Task onConnected(MqttClientConnectedEventArgs arg)
 {
     await Task.Run(() => {
         Console.WriteLine("Bus connected");
         _logger.LogInformation("Bus connected.");
     });
 }
Beispiel #25
0
 /// <summary>
 /// 客户端连接
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void MqttServer_ClientConnected(object sender, MqttClientConnectedEventArgs e)
 {
     if (!subClientIDs.Contains(e.ClientId))
     {
         subClientIDs.Add(e.ClientId);
     }
     //   log.Info(DateTime.Now + $"客户端[{e.ClientId}]已连接,共有" + subClientIDs.Count + "客户端在连接!");
 }
Beispiel #26
0
        private void MqttServer_ClientConnected(object sender, MqttClientConnectedEventArgs e)
        {
            ConnectedMqttClient client = e.Client;

            mqttClients.Add(client.ClientId, client);

            Invoke(new SetTextTb(SetMessageByClientMsg), client, false);
        }
 private void HandleMqttConnected(MqttClientConnectedEventArgs e)
 {
     using (var scope = _serviceScopeFactory.CreateScope())
     {
         var hub = scope.ServiceProvider.GetService <IHubContext <MqttHub> >();
         hub.Clients.All.SendAsync("Connected", e.AuthenticateResult.ResultCode.ToString());
     }
 }
Beispiel #28
0
 private void Server_ClientConnected(object sender, MqttClientConnectedEventArgs e)
 {
     this.Dispatcher.Invoke(() =>
     {
         _model.AllClients.Add(e.ClientId);
     });
     WriteToStatus("客户端" + e.ClientId + "连接");
 }
Beispiel #29
0
 public Task HandleConnectedAsync(MqttClientConnectedEventArgs eventArgs)
 {
     return(Task.Run(() =>
     {
         connectingFailedReason = null;
         startWaitEvent.Set();
     }));
 }
Beispiel #30
0
 private void ClientConnected(object sender, MqttClientConnectedEventArgs e)
 {
     LogHelper.Debug(this, "Client Connected");
     connections.Add(new ConnectionInfo()
     {
         UserName = e.Client.ClientId
     });
 }