1

I'm really new to MQTT protocol and do some tests in ubuntu and openwrt platforms using terminal commands. I have successfully install opensource MQTT broker Mosquitto on openwrt chaos calmer and I now able to publish/subscribe topic using two different terminal windows. Im planning to build a simple GUI application with minimal user interface to publish the MQTT message. I saw that M2Mqtt library for support. But when it comes to the documentation there is no proper guidance for how to connect external MQTT broker.

I followed this document http://www.hivemq.com/blog/mqtt-client-library-encyclopedia-m2mqtt

How can I publish message to MQTT broker hosted externally (in my case virtualbox - on top of openwrt ) with C# ?

1
  • 1
    Post what you have already tried and somebody will likely point out any problems of it Commented Apr 15, 2016 at 18:16

1 Answer 1

3

The Link you mentioned already contains your answer.

To connect to the MQTT broker:

MqttClient client = new MqttClient("broker.hivemq.com");
byte code = client.Connect(Guid.NewGuid().ToString());

To publish a message, do the following:

ushort msgId = client.Publish("/my_topic", // topic
                              Encoding.UTF8.GetBytes("MyMessageBody"), // message body
                              MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE, // QoS level
                              false); // retained
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.