![]() You have many other options, configurations that you can use when posting a message such as security, quality of service (QoS), and more but in this post I want to simply show how easy is to publish and consume MQTT messages. tPayload("Hello world from Java".getBytes()) MqttClient client = new MqttClient("tcp://localhost:1883", MqttClient.generateClientId()) Publishing a message is quite easy, create a MqttClient and use it to post on a topic. Maven DependenciesĪdd the Eclipse Paho dependency to your Maven project Write your first MQTT Applicationįor this example I will write a small Java application, since it is the language that I am using in my global project. You should see the message Hello world in the consumer/subscriber window. Publish $ mosquitto_pub -h 127.0.0.1 -t iot_data -m "Hello world" Open two terminal windows and run the following commands :Ĭonsume $ mosquitto_sub -h 127.0.0.1 -t iot_data Start the MQTT Broker with the default configuration $ /usr/local/sbin/mosquitto Publish and Consume messages ![]()
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |