3

I have installed Mosquitto using brew using

brew install mosquitto

And tested whether it is running using

brew services list

Output

Name       Status  User Plist
mongodb    stopped      
mosquitto  started amit /Users/amit/Library/LaunchAgents/homebrew.mxcl.mosquitto.plist
postgresql stopped      
tomcat     stopped

However, when I try the following from this answer I get command not found

mosquitto_sub -v -t 'test/topic'
-bash: mosquitto_sub: command not found

Do I have to install something else for this to work?

Also, I tried to connect to the broker using a python script, but I get a connection refused message

client = mqtt.Client()
client.on_connect = on_connect_handler
client.on_message = on_message_handler

client.connect("localhost", 1883, 60)
client.loop_forever()

EDIT 1

I solved the first issue of not being able to use mosquitto_sub using brew link mosquitto.

But I still get a connection refused.

amitection
  • 2,696
  • 8
  • 25
  • 46
  • Your Python script cannot work *"as is"* because you have not installed nor imported a mosquitto client. – Mark Setchell Sep 07 '18 at 18:29
  • I have done that. I did not add it to the question cause I thought it was implicit. However, I have figured out the answers. Thanks for taking the time to have a look. – amitection Sep 07 '18 at 18:31
  • Well done! Please add your results as an answer and then you can accept your own answer and bag the points and help the community. – Mark Setchell Sep 07 '18 at 18:37

1 Answers1

11

After some Googling and trying out different things I have figured out the answers to both the questions.

  1. The first issue of not being able to start the Publisher and Subscriber clients was solved using brew link mosquitto. To check how brew link works you can check this post.
  2. Starting the mosquitto broker service as a daemon allowed connections. So simply using brew services start mosquitto -d works. I am not sure why this works instead of starting a normal process.
amitection
  • 2,696
  • 8
  • 25
  • 46