-
-
Save KazChe/6bcafbaf29e10a7f309d3ca2e2a0f706 to your computer and use it in GitHub Desktop.
(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. | |
For someone who got error:
Error: Failure while executing; `cp -pR /private/tmp/d20220220-41397-yjfjvo/ca-certificates/. /usr/local/Cellar/ca-certificates` exited with 1. Here's the output:
Try this:
$ sudo chown -R $(whoami) /usr/local/Cellar
It's work for me.
However, from that other machine I can ping the broker Mac using its OS-given hostname. But publish attempts get "connection refused."
@Stokestack did you ever get this working? MacOS has a firewall turned on by default which refuses connections even if they are on your local network. I've dealt with the same issue when attempting to connect a Raspberry Pi to a TCP server on my Mac. This might be the cause of the issue you'd encountered.
@polyphonic13 It's been a while, so I can't remember! I think I think I did, though. I also was using a Pi as the other node, and I don't think I gave up and ran the broker on the Pi.
Thanks a lot for the note!
my problem is it's not running!
hanpeng@hanpeng ~ % sudo brew services stop mosquitto
Stopping mosquitto
... (might take a while)
==> Successfully stopped mosquitto
(label: homebrew.mxcl.mosquitto)
hanpeng@hanpeng ~ % sudo brew services start mosquitto
==> Successfully started mosquitto
(label: homebrew.mxcl.mosquitto)
hanpeng@hanpeng ~ % sudo brew services info mosquitto
mosquitto (homebrew.mxcl.mosquitto)
Running: ✘
Loaded: ✔
Schedulable: ✘
why it's just connot running. and the version of mosquitto is as below
hanpeng@hanpeng ~ % brew upgrade mosquitto
Warning: mosquitto 2.0.14 already installed
how to do logging of mosquitto connect and disconnect messages on Mac
You can also stop the mosquitto when running through brew by:
$ brew services stop mosquitto