MQTT

Installation of mosquitto from source

Compile libwebsockets

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

Get mosquitto

cd ~/src
hg clone https://bitbucket.org/oojah/mosquitto

cd mosquitto/
hg pull && hg update 1.4
nano config.mk
#Change WITH_WEBSOCKETS:=yes

apt-get install xsltproc
Apply following changes:
diff -r 908c5da1c88d Makefile
--- a/Makefile  Mon Nov 03 08:46:31 2014 +0000
+++ b/Makefile  Wed Sep 09 19:22:28 2015 +0000
@@ -4,14 +4,14 @@
 DOCDIRS=man
 DISTDIRS=man

-.PHONY : all mosquitto docs binary clean reallyclean test install uninstall dist sign copy
+.PHONY : all mosquitto binary clean reallyclean test install uninstall dist sign copy

 all : $(MAKE_ALL)

-docs :
-       set -e; for d in ${DOCDIRS}; do $(MAKE) -C $${d}; done
+binary : mosquitto

-binary : mosquitto
+docs:
+       $(info skipped)

 mosquitto :
        set -e; for d in ${DIRS}; do $(MAKE) -C $${d}; done
@@ -32,7 +32,6 @@

 install : mosquitto
        set -e; for d in ${DIRS}; do $(MAKE) -C $${d} install; done
-       set -e; for d in ${DOCDIRS}; do $(MAKE) -C $${d} install; done
        $(INSTALL) -d ${DESTDIR}/etc/mosquitto
        $(INSTALL) -m 644 mosquitto.conf ${DESTDIR}/etc/mosquitto/mosquitto.conf.example
        $(INSTALL) -m 644 aclfile.example ${DESTDIR}/etc/mosquitto/aclfile.example
diff -r 908c5da1c88d config.mk
--- a/config.mk Mon Nov 03 08:46:31 2014 +0000
+++ b/config.mk Wed Sep 09 19:22:28 2015 +0000
@@ -68,7 +68,7 @@
 WITH_UUID:=yes

 # Build with websockets support on the broker.
-WITH_WEBSOCKETS:=no
+WITH_WEBSOCKETS:=yes

 # Build with client support for SOCK5 proxy.
 WITH_SOCKS:=yes

make

sudo make install 

sudo useradd -r -m -d /var/lib/mosquitto -s /usr/sbin/nologin -g nogroup mosquitto

Mosquitto broker config

#If required, edit or create your config file and create the service user ID.

sudo vim /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 mosquitto

 sudo /usr/local/sbin/mosquitto -c /etc/mosquitto/mosquitto.conf

Trace missing libraries with the use of:

strace ./mosquitto -c mosquitto.conf

create symlink

sudo ln -s /usr/local/lib/libmosquitto.so.1 /usr/lib/
sudo ln -s /usr/local/lib/libwebsockets.so.4.0.0 /usr/lib/

Info for startup script:

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

Test mosquitto

Broker

mosquitto -c mosquitto.conf

Client subscribe to topic

mosquitto_sub -h 127.0.0.1 -t testTopic

Client publish to the topic

mosquitto_pub -d -t testTopic -m "Testing hello world trallalalal"

Current json interface for esp8266

See github project

{"init": {"host": "192.168.178.x", "port": "1883", "clientid": "esp123", "user": "username", "pass": "password",  "interval": "120"}}
{"wifi": {"bssid": "yourbssid", "psk": "yourpsk"}}
{"subscribe": {"host": "192.168.178.x","topic": "/abc/de/fgh"}}
{"publish": {"host": "192.168.178.x", "topic": "/test", "message": "Hello World"}}

MQTT webinterface/client

sudo apt-get install apache2
cd /var/www/html/
git clone https://github.com/hivemq/hivemq-mqtt-web-client.git

Go to localhost/mqtt in a browser this will show HiveMQ
Host: 192.168.178.x
Port: 9001

sources:

– https://goochgooch.wordpress.com/2014/08/01/building-mosquitto-1-4/
– http://michaelconnors.net/article/462/hello-mqtt

One Comment

Leave a Reply

Your email address will not be published. Required fields are marked *