Esempio n. 1
0
        private static void _subscribe(MqttConfig cfg)
        {
            //System.Threading.Timer tmr;
            //"192.168.9.21"

            var client = new uPLibrary.Networking.M2Mqtt.MqttClient(cfg.server);

            client.ProtocolVersion         = uPLibrary.Networking.M2Mqtt.MqttProtocolVersion.Version_3_1_1;
            client.MqttMsgSubscribed      += Client_MqttMsgSubscribed;
            client.MqttMsgPublishReceived += Client_MqttMsgPublishReceived;
            client.MqttMsgPublished       += Client_MqttMsgPublished;

            if (!string.IsNullOrWhiteSpace(cfg.username))
            {
                client.Connect(Guid.NewGuid().ToString(), cfg.username, cfg.password);
            }
            else
            {
                client.Connect(Guid.NewGuid().ToString());
            }

            var channels = new List <string>();
            var qoss     = new List <byte>();

            {
                foreach (var s in cfg.subscriptions)
                {
                    channels.Add(s.channel);
                    qoss.Add(s.qos);
                }
            }

            /*client.Subscribe(new string[] {"house/serverroom/temp"}, new byte[] { 0});*/
            client.Subscribe(channels.ToArray(), qoss.ToArray());

            Console.WriteLine("Type 'q' to quit");
            string text = null;

            do
            {
                text = Console.ReadLine();
            } while(text != "q");

            client.Disconnect();
        }
Esempio n. 2
0
 public XamMqtt(MqttConfig config, ILogger <XamMqtt> log)
 {
     _config = config; _logger = log;
 }