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?
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?
To test and see if you can access your MQTT server from outside world (outside of your VM or local machine), you can install one of the MQTT publishing and monitoring tools such as MQTT-Spy on your outside-world machine and then subscribe for '#" (meaning all the topics).
You can follow this by the method @hardillb mentioned in his answer above and test back and forth such as this:
On the machine with Mosquitto Server running,
On the outside-word machine with mqtt-spy running,
I have mainly mentioned mqtt-spy since it's multi-platform and easy to use. You can go with any other tool really. And also to my knowledge to run the
mosquitto_sub
andmosquitto_pub
you need to have mosquitto-clients installed on your Linux machine running the test (in my case Ubuntu) which can be done easily by,sudo apt-get install mosquitto-clients
If you are using Windows, open up a command prompt and type 'netstat -an'.
If your server is running, you should be able to see the port 1883.
If you cannot go to Task Manager > Services and start/restart the Mosquitto server from there. If you cannot find it here too, your installation of Mosquitto has not been successful.
A more detailed tutorial for setting up Mosquitto with Windows / is linked here.
The OP has not defined the scope of testing, however, simple (gross) 'smoke testing' an install should be performed before any time is invested with functionality testing.
How to test if application is installed ('smoke-test')
Log into the
mosquitto
server's command line and type:If mosquitto is installed the machine will return:
In separate terminal windows do the following:
Start the broker:
Start the command line subscriber:
Publish test message with the command line publisher:
As well as seeing both the subscriber and publisher connection messages in the broker terminal the following should be printed in the subscriber terminal:
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.