Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to test the `Mosquitto` server?

I am new to Mosquitto and MQTT, I downloaded the Mosquitto server library but I do not know how to test it.

Is there any way to test the Mosquitto server?

like image 352
user2121 Avatar asked Nov 03 '14 14:11

user2121


People also ask

How do I test MQTT messages?

To view MQTT messages in the MQTT clientIn the AWS IoT console , in the left menu, choose Test and then choose MQTT test client. In the Subscribe to a topic tab, enter the topicName to subscribe to the topic on which your device publishes.

How do I ping my MQTT server?

MQTT uses a TCP/IP connection that is normally left open by the client so that is can send and receive data at any time. To detect a connection failure MQTT uses a ping system where it sends messages to the broker at a pre-determined interval if no messages have been sent after a certain period (KeepAlive).

How do you monitor mosquitto?

Download the files, go through the README file, point your Dashboard to your Mosquitto Broker details, and your Dashboard is up and running. The dashboard runs on a browser (tested on Chrome) and has been built using Responsive Web Design. You can run the dashboard on your mobile phone's browser too.

How do I start a mosquitto server?

Starting Mosquitto on Windows To start the broker manually open a command prompt and go to the mosquitto install directory and type mosquitto. for help.


2 Answers

In separate terminal windows do the following:

  1. Start the broker:

    mosquitto 
  2. Start the command line subscriber:

    mosquitto_sub -v -t 'test/topic' 
  3. Publish test message with the command line publisher:

    mosquitto_pub -t 'test/topic' -m 'helloWorld' 

As well as seeing both the subscriber and publisher connection messages in the broker terminal the following should be printed in the subscriber terminal:

test/topic helloWorld 

EDIT:

It is worth pointing out that from v2.0.0 of Mosquitto it will only be listening for connections on the loopback interface by default. If you want to access the broker from machines other than the one it is installed on you will need to edit the config file (and pass it to the broker with the -c option e.g. mosquitto -c /path/to/mosquitto.conf) to enable listening on other interfaces. Details can be found in the v2.0.0 release notes here

like image 58
hardillb Avatar answered Sep 20 '22 02:09

hardillb


Start the Mosquitto Broker
Open the terminal and type

mosquitto_sub -h 127.0.0.1 -t topic

Open another terminal and type
mosquitto_pub -h 127.0.0.1 -t topic -m "Hello"

Now you can switch to the previous terminal and there you can able to see the "Hello" Message.One terminal acts as publisher and another one subscriber.

like image 39
Ashal Avatar answered Sep 20 '22 02:09

Ashal