This project is read-only.
Create and initialize the Client:

        public void Initialize()
        {
            var broker = "192.168.10.125";
            var port = 1883;
            var user = "my_name";
            var pwd = "secret_stuff!";
            var myClientID = "foo_bar_baz";

            // create the Client
            m_client = new MQTTClient(broker, port);
            // authenticate with the server
            m_client.Connect(myClientID, user, pwd);
        }



Subscribe to a Topic:

            var topic = "path/topic";

            // hook up the event handler
            m_client.MessageReceived += m_client_MessageReceived;

            // subscribe to a topic
            m_client.Subscriptions.Add(topic, QoS.FireAndForget);
...

        void m_client_MessageReceived(string topic, QoS qos, byte[] payload)
        {
            // this is called when a subscribed topic gets a message
            var message = Encoding.ASCII.GetString(payload);
            Debug.WriteLine(
                 string.Format("Message received for topic: {0}\r\n\t{1}", 
                 topic, message));
        }



And publish to a Topic:

        var topic = "path/TopicName";
        m_client.Publish(topic, "{ \"Message\":\"Hello World\" }", QoS.FireAndForget, false);

Last edited May 14, 2015 at 7:08 PM by ctacke, version 3