How-to: Rasbperry Pi – Install mosquitto with websockets enable

Revision for “How-to: Rasbperry Pi – Install mosquitto with websockets enable” created on March 23, 2015 @ 19:40:04 [Autosave]

Title
How-to: Rasbperry Pi - Install mosquitto with websockets enable
Content
#https://goochgooch.wordpress.com/2014/08/01/building-mosquitto-1-4/ sudo apt-get update &amp;&amp; sudo apt-get install build-essential rpm cmake libssl-dev mercurial uuid-dev xsltproc docbook-xsl mkdir src cd src wget http://git.warmcat.com/cgi-bin/cgit/libwebsockets/snapshot/libwebsockets-1.3-chrome37-firefox30.tar.gz tar -xzvf libwebsockets-1.3-chrome37-firefox30.tar.gz cd libwebsockets-1.3-chrome37-firefox30/ mkdir build cd build sudo cmake .. -DOPENSSL_ROOT_DIR=/usr/bin/openssl sudo make sudo make install cd ~/src hg clone https://bitbucket.org/oojah/mosquitto cd mosquitto/ hg pull &amp;&amp; hg update 1.4 nano config.mk #Change WITH_WEBSOCKETS:=yes make #make test sudo make install sudo useradd -r -m -d /var/lib/mosquitto -s /usr/sbin/nologin -g nogroup mosquitto <pre>sudo ldconfig</pre> #If need be, edit or create your config file and create the service user ID. sudo nano /etc/mosquitto/mosquitto.conf autosave_interval 1800 persistence true persistence_file m2.db persistence_location /tmp/ connection_messages true log_timestamp true listener 1883 listener 9001 127.0.0.1 protocol websockets #Start it #sudo /usr/local/sbin/mosquitto -c /etc/mosquitto/mosquitto.conf sudo nano /etc/init.d/mosquitto #! /bin/sh ### BEGIN INIT INFO # Provides: mosquitto # Required-Start: $remote_fs $syslog # Required-Stop: $remote_fs $syslog # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: mosquitto MQTT v3.1 message broker # Description: # This is a message broker that supports version 3.1 of the MQ Telemetry # Transport (MQTT) protocol. # # MQTT provides a method of carrying out messaging using a publish/subscribe # model. It is lightweight, both in terms of bandwidth usage and ease of # implementation. This makes it particularly useful at the edge of the network # where a sensor or other simple device may be implemented using an arduino for # example. ### END INIT INFO set -e PIDFILE=/tmp/mosquitto.pid DAEMON=/usr/local/sbin/mosquitto # /etc/init.d/mosquitto: start and stop the mosquitto MQTT message broker test -x ${DAEMON} || exit 0 umask 022 . /lib/lsb/init-functions # Are we running from init? run_by_init() { ([ "$previous" ] &amp;&amp; [ "$runlevel" ]) || [ "$runlevel" = S ] } export PATH="${PATH:+$PATH:}/usr/sbin:/sbin" case "$1" in start) log_daemon_msg "Starting Mosquitto message broker" "mosquitto" if start-stop-daemon --start --quiet --oknodo --background --make-pidfile --pidfile ${PIDFILE} --exec ${DAEMON} -- -c /etc/mosquitto/mosquitto.conf ; then log_end_msg 0 else log_end_msg 1 fi ;; stop) log_daemon_msg "Stopping Mosquitto message broker" "mosquitto" if start-stop-daemon --stop --quiet --oknodo --pidfile ${PIDFILE}; then log_end_msg 0 rm -f ${PIDFILE} else log_end_msg 1 fi ;; reload|force-reload) log_daemon_msg "Reloading configuration not supported" "mosquitto" ;; restart) log_daemon_msg "Restarting Mosquitto message broker" "mosquitto" if start-stop-daemon --stop --quiet --oknodo --retry 30 --pidfile ${PIDFILE}; then rm -f ${PIDFILE} fi if start-stop-daemon --start --quiet --oknodo --background --make-pidfile --pidfile ${PIDFILE} --exec ${DAEMON} -- -c /etc/mosquitto/mosquitto.conf ; then log_end_msg 0 else log_end_msg 1 fi ;; try-restart) log_daemon_msg "Restarting Mosquitto message broker" "mosquitto" set +e start-stop-daemon --stop --quiet --retry 30 --pidfile ${PIDFILE} RET="$?" set -e case $RET in 0) # old daemon stopped rm -f ${PIDFILE} if start-stop-daemon --start --quiet --oknodo --background --make-pidfile --pidfile ${PIDFILE} --exec ${DAEMON} -- -c /etc/mosquitto/mosquitto.conf ; then log_end_msg 0 else log_end_msg 1 fi ;; 1) # daemon not running log_progress_msg "(not running)" log_end_msg 0 ;; *) # failed to stop log_progress_msg "(failed to stop)" log_end_msg 1 ;; esac ;; status) status_of_proc -p ${PIDFILE} ${DAEMON} mosquitto &amp;&amp; exit 0 || exit $? ;; *) log_action_msg "Usage: /etc/init.d/mosquitto {start|stop|reload|force-reload|restart|try-restart|status}" exit 1 esac exit 0 &nbsp; sudo chown root:root /etc/init.d/mosquitto sudo chmod +x /etc/init.d/mosquitto sudo update-rc.d mosquitto defaults sudo update-rc.d mosquitto enable sudo /etc/init.d/mosquitto start
Excerpt


OldNewDate CreatedAuthorActions
March 23, 2015 @ 19:40:04 [Autosave] Martin
March 23, 2015 @ 19:35:48 Martin
January 10, 2015 @ 16:02:00 Martin

4 thoughts on “How-to: Rasbperry Pi – Install mosquitto with websockets enable

  1. Hi,
    First, thanks a lot for the tutorial, it saved me!
    I´m able to start the mosquitto manually, and it works fine, but when I configure to start up on boot, it dosen´t work.
    This is the message I get:

    root@raspberrypi:/var/log/mosquitto.log# service mosquitto status
    mosquitto.service – LSB: mosquitto MQTT v3.1 message broker
    Loaded: loaded (/etc/init.d/mosquitto)
    Active: active (exited) since Wed, 13 May 2015 15:48:37 -0300; 21min ago
    CGroup: name=systemd:/system/mosquitto.service

    May 13 15:48:37 raspberrypi mosquitto[2699]: [85B blob data]
    May 13 15:48:37 raspberrypi mosquitto[2699]: Try ‘start-stop-daemon –help’ for more information.
    May 13 15:48:37 raspberrypi mosquitto[2699]: failed!

    Could you give me some help, I tried everyting that I know to put it to work, but with no success.
    I apreciate any device you could give me.

    Thanks a lot!

  2. Hello,
    I followed all the steps and am having trouble, you will be able to help me?

    The error is:

    root @ webbaby: / etc / mosquitto # mosquitto -c /etc/mosquitto/mosquitto.conf
    1445001385: mosquitto version 1.4.4 (build date 10/16/2015 08: 28: 17-0300) starting
    1445001385: Config loaded from /etc/mosquitto/mosquitto.conf.
    1445001385: Opening ipv4 listen socket on port 9001.
    1445001385: Opening ipv6 listen socket on port 9001.
    1445001385: Opening websockets listen socket on port 1883.
    1445001389: New connection from 192.168.0.17 on port 9001.
    1445001389: Socket error on client , disconnecting.
    1445001390: New connection from 192.168.0.17 on port 9001.
    1445001390: Socket error on client , disconnecting.

    • Hmm, not sure, but it seems like error on the client side not authenticating.

      Try to turn off the acl and passwd setting in conf file, if you enabled them

  3. Hi, this isn’t needed anymore. Simply add the repo from mosquitto.org and install from that.

    That version includes websockets, all you need to do is to add a conf file.

    I’ve put some information on my blog to this effect.

Comments are closed.