terça-feira, 22 de dezembro de 2015

First steps with MQTT using Mosquitto

In this post I will quickly show the steps I followed to install and test mosquitto, a MQTT server.

Installing and starting Mosquitto

In my case I simply added the yum repository and then, as root, I run yum install mosquitto.

After a few minutes it was installed. To install it for your system, please see mosquitto download page.

After the installation, you can run mosquitto in the command line and the server will be started:

Running mosquitto. You can also run in daemon mode, see the mosquitto man page for further information

To test the installation I suggest to install the mosquito clients: yum install mosquitto-clients.x86_64. Once you install the clients, let's use the mosquito_sub tool to subscribe to the topic fxapps/test:

Subscribing to the topic fxapps/test. The -q parameter sets the QoS. For further information see mosquitto_pub man page.
 Now we are able to public strings to it using mosquito_pub:

Publishing a message to the topic fxapps/test. For further information see mosquitto_pub man page.
 Finally you should be able to see the message being received on our MOSQUITTO_SUB tab:

Receiving the message using mosquitto_sub.

So far we show how to access a local MQTT server, but it is also possible to access remote servers (of course it is, MQTT and IoT are all about cloud!).

Accessing the public MQTT Mosquitto server 

 Using the mentioned tools mosquitto_pub and mosquitto_sub, we can access the public mosquitto server: http://test.mosquitto.org/.  AS a test, we will create the topic  fxapps/test and publish messages to it:

We used a public remote MQTT server: http://test.mosquitto.org/


MQTT is really simple and mosquitto is easy to use and install. If you know JMS, you know MQTT!

I hope I will come back with more posts about MQTT with JavaFX, jBPM, arduino etc

Nenhum comentário:

Postar um comentário