Exemplo n.º 1
0
        public void Initialize()
        {
            _server.Start();
            _server.InjectClient("HA4IoT.Loopback", _clientCommunicationAdapter);

            _client.ConnectAsync().Wait();
            _client.SubscribeAsync(new TopicFilter("#", MqttQualityOfServiceLevel.AtMostOnce)).Wait();

            _log.Info("MQTT client (loopback) connected.");
        }
Exemplo n.º 2
0
        private static MqttClient ConnectTestClient(string clientId, MqttApplicationMessage willMessage, MqttServer server)
        {
            var adapterA = new TestMqttCommunicationAdapter();
            var adapterB = new TestMqttCommunicationAdapter();

            adapterA.Partner = adapterB;
            adapterB.Partner = adapterA;

            var client = new MqttClient(new MqttClientOptions(), adapterA);

            server.InjectClient(clientId, adapterB);
            client.ConnectAsync(willMessage).Wait();
            return(client);
        }