Mosquitto MQTT Broker

From SME Server
Jump to navigationJump to search

About

Eclipse Mosquitto™ is an open source (EPL/EDL licensed) message broker that implements the MQTT protocol versions 3.1 and 3.1.1. MQTT provides a lightweight method of carrying out messaging using a publish/subscribe model. This makes it suitable for "Internet of Things" messaging such as with low power sensors or mobile devices such as phones, embedded computers or microcontrollers like the Arduino.

This description is about how to install the mosquitto broker service on SME9/Centos6.


Warning.png Warning:
This not longer appears to install due to requires for libwebsocket. There does not appear to be a libwebsocket package available for CentOS 6 and it would need to be built manually. They may prove to be difficult/impossible due to requires in the libwebsocket requires. https://forums.contribs.org/index.php/topic,53906.0.html


Installation

Setting the Mosquitto MQTT YUM repositories

 /sbin/e-smith/db yum_repositories set mosquitto repository \
 Name 'Mosquitto MQTT CentOS-$releasever' \
 BaseURL 'http://download.opensuse.org/repositories/home:/oojah:/mqtt/CentOS_CentOS-$releasever/' \
 EnableGroups no \
 GPGCheck yes \
 GPGKey 'http://download.opensuse.org/repositories/home:/oojah:/mqtt/CentOS_CentOS-$releasever//repodata/repomd.xml.key' \
 Visible no \
 status disabled
 signal-event yum-modify

Yum Installation

 yum install mosquitto mosquitto-clients --enablerepo=mosquitto

Create a 'mosquitto' user

 adduser mosquitto

Set SME Configuration

 config set mosquitto service
 config setprop mosquitto TCPPort 1883
 config setprop mosquitto access public
 config show mosquitto
 
 signal-event remoteaccess-update
 

Set custom template for /etc/hosts.allow

 mkdir /etc/e-smith/templates-custom/etc/hosts.allow
 cd    /etc/e-smith/templates-custom/etc/hosts.allow
 touch mosquitto
 

Edit the file 'mosquitto' to have the following content:

{
   $DB->hosts_allow_spec('mosquitto');
}

and expand the template:

expand-template /etc/hosts.allow

Enable As Service

 chkconfig mosquitto --add
 chkconfig mosquitto --level 2345 on
 cd /etc/rc.d/rc7.d
 ln -s ../init.d/mosquitto S50mosquitto

Setup Log Path

 mkdir /var/log/mosquitto
 

Enable Write Access To Log

 cd /var/log/mosquitto
 chmod mosquitto:mosquitto .	

Update Mosquitto Configuration

In /etc/mosquitto/mosquitto.conf

Add line:

 user mosquitto

Add/change line:

 log_dest file /var/log/mosquitto/mosquitto.log

Start Mosquitto Service

 service mosquitto start

Enable Port 1883 Forwarding

On your internet gateway router, enable TCP port 1883 to allow MQTT clients access the broker.

Testing Access To The Broker

On a command line on your server use something like:

mosquitto_pub -d -t sensors/temperature -m 32 -q 1

If you get an output like below, your server is functional:

Client mosqpub/22329-franka sending CONNECT
Client mosqpub/22329-franka received CONNACK
Client mosqpub/22329-franka sending PUBLISH (d0, q1, r0, m1, 'sensors/temperature', ... (2 bytes))
Client mosqpub/22329-franka received PUBACK (Mid: 1)
Client mosqpub/22329-franka sending DISCONNECT

References