Skip to content

Notification Service Configuration

Luis edited this page Sep 15, 2015 · 1 revision

Install Mosquitto

  1. Download mosquitto

    wget http://mosquitto.org/files/source/mosquitto-1.4.3.tar.gz

  2. Install some packages

    sudo apt-get install libwrap0-dev

    sudo apt-get install libssl-dev

    sudo apt-get install uuid-dev

  3. Uncompress targz

    tar zxf mosquitto-1.4.3.tar.gz

  4. Compile and install

    make

    make install

    ldconfig

    make clean

    iptables -A INPUT -p tcp -m tcp --dport 1883 -j ACCEPT

*If there is some error while compiling, go to this webpage:

https://goochgooch.wordpress.com/2014/08/01/building-mosquitto-1-4/


Start Mosquitto

  1. Starting mosquitto

    Open a terminal and type:

     mosquitto -p portnumber
    
  2. Checking mosquitto is running

    Open a terminal and type:

     ps -ef | grep mosq && netstat -tln | grep portnumber
    

Test Application

*You will need to install mqtt through npm install mqtt -g

example.js:

var mqtt    = require('mqtt');
var client  = mqtt.connect('mqtt://localhost:6969');
 
client.on('connect', function () {
  client.subscribe('presence');
  console.log("Connected");
  client.publish('presence', 'Hello mqtt');
});

client.on('error',function(error) {
    console.log(error);
});
 
client.on('message', function (topic, message) {
  // message is Buffer
  console.log(message.toString());
  client.end();
});

Run:

node example.js.

You must see in the consolelog “Hello mqtt”


Mosquitto Configuration File

Full information about configuration file :

https://eclipse.org/mosquitto/man/mosquitto-conf-5.php

You can load a configuration file with -c option. By default mosquitto load mosquito.conf file.

mosquito -c configurationfile

Configuration lines start with a variable name. The variable value is separated from the name by a single space.

1.Authentication

There are a few possibilities of authentication

  1. The simplest option is to have no authentication at all.This is the default if no other options are given.

  2. You can use a password file option to define the valid usernames and poasswords. You must be sure to use network encryption if you are using this options otherwise they will be vulnerable to interception.

  3. Certificate based encryption.

*You can use all of them at once.


Documentation

Mosquitto: http://mosquitto.org/documentation/

Mqtt:. https://www.npmjs.com/package/mqtt

Clone this wiki locally