Mosquitto Build Notes (Linux) - bapowell/bapowell.github.io GitHub Wiki
- Tested with RHEL-7, Ubuntu-14.04LTS, and Raspbian-Jessie on Raspberry Pi 2.
- References:
RHEL: sudo yum install c-ares-devel libuuid-devel openssl-devel -y
Ubuntu: sudo apt-get install git cmake libc-ares-dev uuid-dev libssl-dev zlib1g-dev
RasPi: sudo apt-get install git cmake libc-ares-dev uuid-dev libssl-dev daemon
wget http://git.libwebsockets.org/cgi-bin/cgit/libwebsockets/snapshot/libwebsockets-1.6.2.tar.gz
(also tested with http://git.libwebsockets.org/cgi-bin/cgit/libwebsockets/snapshot/libwebsockets-1.6.0-chrome48-firefox42.tar.gz)
tar xzvf libwebsockets-1.6.2.tar.gz
cd libwebsockets-1.6.2
mkdir build
cd build
RHEL: cmake .. -DLIB_SUFFIX=64
Ubuntu: cmake .. -DLIB_SUFFIX=64
RasPi: cmake ..
sudo make install
RHEL: sudo ln -s /usr/local/lib64/libwebsockets.so.6 /lib64/libwebsockets.so.6
Ubuntu: sudo ln -s /usr/local/lib64/libwebsockets.so.6 /lib/libwebsockets.so.6
RasPi: sudo ldconfig #rebuild the library cache
cd ../..
wget http://mosquitto.org/files/source/mosquitto-1.4.7.tar.gz
tar xzvf mosquitto-1.4.7.tar.gz
cd mosquitto-1.4.7
- To enable websockets, modify WITH_WEBSOCKETS:=yes
- If don't want to install dependencies, modify WITH_TLS:=no, WITH_TLS_PSK:=no, WITH_UUID:=no, WITH_SRV:=no
- If encounter problems running make, and need to re-do some steps, run "make clean" before running make again.
make
- Compiled mosquitto and mosquitto_passwd executables will be located in the src subdirectory.
- Compiled mosquitto_pub and mosquitto_sub executables will be located in the client subdirectory.
- Compiled libmosquitto.* will be located in the lib subdirectory.
sudo make install
- Will install the following:
- /usr/local/sbin/mosquitto
- /usr/local/include/mosquitto_plugin.h
- /usr/local/bin/mosquitto_passwd
sudo groupadd mosquitto
sudo useradd -s /sbin/nologin mosquitto -g mosquitto -d /var/lib/mosquitto
- Note: This will add autostart capability, using SystemD.
- Install mosquitto ("sudo make install"; see above).
- Add mosquitto user (see above).
- Create /etc/systemd/system/mosquitto.service file:
[Unit]
Description=Mosquitto MQTT v3.1/v3.1.1 server
Wants=network.target
Documentation=http://mosquitto.org/documentation/
[Service]
Type=simple
User=mosquitto
Group=mosquitto
ExecStart=/usr/local/sbin/mosquitto -c /etc/mosquitto/mosquitto.conf
Restart=on-failure
SyslogIdentifier=Mosquitto
[Install]
WantedBy=multi-user.target
- Create /etc/mosquitto/mosquitto.conf
- Example content is shown below under the Test section.
sudo systemctl daemon-reload
- Starting the service:
- sudo systemctl start mosquitto.service
- Stopping the service:
- sudo systemctl stop mosquitto.service
- To enable Mosquitto to run automatically at boot and upon crashes:
- sudo systemctl enable mosquitto.service
- To disable:
- sudo systemctl disable mosquitto.service
- For logging, SystemD uses /var/log/system.log. To filter the log use:
- sudo journalctl -f -u mosquitto -o cat
- Ref: http://www.dynacont.net/documentation/linux/Useful_SystemD_commands
listener 1883
protocol mqtt
listener 9001
protocol websockets
http_dir /home/johndoe/mqtt/ws/http # note that this folder needs to exist; otherwise mosquitto will choke upon startup
-
Before running, kill any processes using port 1883 or 9001.
-
If installed ("sudo make install"; see above):
mosquitto -v -c mosquitto_ws.conf
-
If not installed, then from the folder where you built mosquitto:
src/mosquitto -v -c mosquitto_ws.conf
-
To use mosquitto_sub/pub clients, in separate terminal session, and from the folder where you built mosquitto:
LD_LIBRARY_PATH=./lib/ client/mosquitto_sub -v -t test
LD_LIBRARY_PATH=./lib/ client/mosquitto_pub -t test -m "hello"
- Copy the four files found here: https://github.com/eclipse/paho.mqtt.javascript/tree/master/utility into /home/johndoe/mqtt/ws/http
- Copy the https://github.com/eclipse/paho.mqtt.javascript/blob/master/src/mqttws31.js file into that same folder.
- Edit index.html, removing the "../src/" path prefix in the <script> tag for including mqttws31.js.
- After starting mosquitto (specifying conf file shown above), open browser and navigate to http://mosquitto-host:9001/