Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
(from : https://simplifiedthinking.co.uk/2015/10/03/install-mqtt-server/ )
Installing Brew
The Mosquitto MQTT Server can be easily installed using Homebrew. If it’s not installed on your system already, then a quick visit to the homepage will give you all you need to get going. Homebrew is an OS X Package Manager for installing and updating non-Mac OS X utilities that are more commonly found in other variants of Linux. To install the basic package manager run the following command.
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Installing Mosquitto MQTT
Let’s use our new Homebrew installation to download and install the necessary Mosquitto binaries. This will also download additional libraries required to support secure access via OpenSSL.
brew install mosquitto
The install script finishes by providing the instructions to start the MQTT server on startup.
ln -sfv /usr/local/opt/mosquitto/*.plist ~/Library/LaunchAgents
Finally, to save a restart, the server can be started now by running
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mosquitto.plist
Now you can test the installation and ensure the server is running successfully. Open a new command window and start a listener.
mosquitto_sub -t topic/state
In another window, send a message to the listener.
mosquitto_pub -t topic/state -m "Hello World"
Nicely done.
Installing the Python Libraries
To create the link between Python and MQTT we need to install the Python Eclipse MQTT library. Visit here for the latest downloads and follow the link to download the required version. Specifically, I downloaded these Python Libraries.
Once downloaded, unpack the tar file and install the library
tar xvf org.eclipse.pho.mqtt.python-1.1.tar
cd org.eclipse.pho.mqtt.python-1.1
sudo python setup.py install
And that’s it. We’re ready to start sending and receiving MQTT messages around the home. There are a vast number of additional options that can be set up around the MQTT server – security is an obvious choice, Quality of Service, users, etc. I’m keeping it simple for now.
@Khalian

This comment has been minimized.

Copy link

commented Mar 29, 2017

launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mosquitto.plist
/usr/local/Cellar/mosquitto/1.4.11_2/homebrew.mxcl.mosquitto.plist: Operation not permitted

Please write a working script in case you wish to expose a gist as public.

@christophevg

This comment has been minimized.

Copy link

commented Dec 12, 2017

To initially launch mosquito and also have it restarted afterwards (e.g. on reboot) use the Homebrew supplied support:

$ brew services start mosquitto
@lon-io

This comment has been minimized.

Copy link

commented Feb 22, 2018

Thanks @christophevg

@anujdeshpande

This comment has been minimized.

Copy link

commented Apr 26, 2018

I had to run brew link mosquitto to get mosquitto_sub and mosquitto_pub to work.
also, in the latest brew you can simply start/stop the broker with brew services start mosquitto. Check the active services with brew services list

@ssaenz11

This comment has been minimized.

Copy link

commented May 4, 2018

How do i change the port to 8083?

@daz

This comment has been minimized.

Copy link

commented Jun 26, 2018

@ssaenz11 change this line in /usr/local/etc/mosquitto/mosquitto.conf


# Port to use for the default listener.
#port 1883

@ugifractal

This comment has been minimized.

Copy link

commented Nov 29, 2018

for someone who got error when running brew link

Linking /usr/local/Cellar/mosquitto/1.5.4_1... 
Error: Could not symlink sbin/mosquitto
/usr/local/sbin is not writable.

try this:

  sudo mkdir -p /usr/local/sbin
  sudo chown -R $(whoami) /usr/local/sbin
@TheDanielz3

This comment has been minimized.

Copy link

commented Dec 4, 2018

nice tutorial i love it and solve my problems on my mac 🗡

@mkormendy

This comment has been minimized.

Copy link

commented Jan 20, 2019

I opted to have mine run on startup without a user logging in. To do so, I did:

sudo cp /usr/local/opt/mosquitto/*.plist /Library/LaunchDaemons
sudo chown root:wheel /Library/LaunchDaemons/homebrew.mxcl.mosquitto.plist

Then change the user in the mosquitto config file:

nano /usr/local/etc/mosquitto/mosquitto.conf

(look for line that has #user mosquitto, uncomment it and change mosquitto to the username that installed mosquitto with homebrew.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.