MQTT Tutorial – Getting Started Guide

Introduction

Bevywise MQTT Broker acts as a perfect middleware or central server connected securely to collect data from edge devices, store them into any big data engines, and send data to the subscribed MQTT Clients. This documentation provides a complete MQTT tutorial – Getting started guide for developers.

Installation and Setup

MQTTRoute is available for download for Windows / Windows servers (32 & 64 bit), Linux, MAC, and Raspbian. The binaries are available as a zip archive for Linux, Mac, and Raspbian and as a self-extracting exe for the Windows OS.

Windows Setup:

Double click the downloaded exe and follow the instruction in the wizard and install the MQTTRoute. By default, the product will be installed inside the C:\Bevywise\MQTTRoute folder. You can change the folder during the installation. Besides, For starting the MQTT Broker, the shortcuts and start menus will be created. For a demo, refer to our installation video.

For Linux, MAC, and Raspberry:

For all other operating systems, you can unzip the archive in the desired location and use the sh files present inside the /Bevywise/MQTTRoute/bin to start the MQTT Broker.

Running the Broker

For Windows

To start MQTTBroker in Windows:

  • You can run the MQTTBroker with multiple ways
  • Double click the “runbroker.bat” file inside the Bevywise/MQTTRoute/bin folder.
  • Open cmd and go to Bevywise/MQTTBroker/bin folder. Next, type “runbroker.bat” and hit enter.

To stop MQTTBroker in Windows:

  • Double click or run the “stopbroker.bat” via cmd, which is inside the Bevywise/MQTTRoute/bin folder.

For Other Operating System

To start MQTTBroker in other OS:

  • Open the terminal and go to Bevywise/MQTTRoute/bin.
  • Type “sh runbroker.sh” and hit enter.

To stop MQTTBroker in other OS:

  • On the terminal, go to Bevywise/MQTTRoute/bin.
  • Type “sh stopbroker.sh” and hit enter.

Configuring Bevywise MQTT broker

The MQTTRoute can be configured using the “broker.conf” file inside the conf folder.

broker.conf

[CONFIG]
PORT_NO = 1883
WS_PORT_NO = 10443

TLS_ENABLED = FALSE
# TLS_PORT must be 88xx.
TLS_PORT_NO = 8883
WSS_PORT_NO = 11443

########################Authentication Details######################

[AUTHENTICATION]
AUTHENTICATION_ENABLED = NO
# YES || NO

######################## UserInterface Details ######################

[UI]
UI_Http_Port = 8080
LIST_API_CLIENTS = FALSE

How to check the broker port

Broker port refers to the port number in which the MQTT Broker starts running. By default, the broker will start listening in “1883”.

You can modify the port by editing the “broker.conf” file.

  • Open Bevywise/MQTTRoute/conf folder
  • In that, open “broker.conf” file. [ If you are a Windows user, you can either use a note pad or sublime to open the file ]
  • In “broker.conf” file, specify the port number in
  • PORT_NO = 1883
  • Save the file and start running the MQTT broker.

How to enable authentication

  • Open Bevywise/MQTTRoute/conf folder.
  • In that, open “broker.conf” file. [ If you are a Windows user, you can either use a note pad or sublime to open the file ].
  • In broker.conf file, enable authentication field to connect your edge devices more securely. By default, it takes the value as NO.
  • AUTHENTICATION_ENABLED = YES
  • Save the file and start running the MQTT broker.

If authentication is enabled, you need to use the MQTT username and password when the edge device is connected. The username and the password should be specified in the Broker User interface.

How to check the Websocket connection Port

WS_PORT_NO specifies the port at which the broker listens for the WebSocket connection.

  • Open Bevywise/MQTTRoute/conf folder
  • In that, open “broker.conf” file.[ If you are a Windows user, you can either use a note pad or sublime to open the file ]
  • In “broker.conf” file, specify the port number in
  • WS_PORT_NO = 10443. By default, it takes the value of 80
  • Save the file and start running the MQTT broker.

How to check the Secured Websocket connection Port

WSS_PORT_NO specifies the port at which the broker listens for the secured WebSocket connection when the TLS is enabled.

  • Open Bevywise/MQTTRoute/conf folder
  • In that, open “broker.conf” file. [ If you are a Windows user, you can either use a note pad or sublime to open the file ]
  • In “broker.conf” file, specify the port number in
  • WSS_PORT_NO = 11443. By default, it takes the value of 443
  • Save the file and start running the MQTT broker.

How to check the UI HTTP Port

  •  Web UI of MQTTRoute uses the port 8080 by default. If you wish to set the port manually.
  • Open Bevywise/MQTTRoute/conf folder
  • In that, open “broker.conf” file. [ If you are a Windows user, you can either use a note pad or sublime to open the file ].
  • In “broker.conf” file, specify the port number in UI_Http_Port = 11443.
  • Save the file and start running the MQTT broker.

Running MQTT Broker with TLS/SSL enabled

Bevywise MQTTBroker has a self-signed root, server, and client certificate by default inside the Certificate folder[Bevywise/MQTTRoute/Certificate]. For development purposes, if you don’t have certificates from authorized CA, you can use these default certificates. To connect your client with TLS/SSL, just copy/paste the client certificate & root certificate on the client-side or set the path of the client & root certificate. The Client certificate is in the Certificate/client folder, and the root certificate is in theCertificate/root folder.

Other than the default certificate, you can create your own self-signed ones using OpenSSL, or you can create free certificates from Let’s Encrypt Once you created certificates, place the certificates in the following folder:

  • Broker or Server certificate and Key file MUST be present in ./Certificate/server folder.
  • Client certificate and Key file MUST be present in ./Certificate/client folder.
  • CA Certificate MUST present in ./Certificate/root folder.
  • Broker and Client certificates MUST be signed by the same CA.

How to enable TLS/SSL in MQTT Broker

  • Open Bevywise/MQTTRoute/conf folder
  • In that, open broker.conf file. [ For windows user use notepad or sublime to open the file]
  • In broker.conf file, change
  • TLS_ENABLED = TRUE
  • Save the file and start the MQTT broker.

How to check the TLS Port

TLS_PORT_NO, Specifies the port in which the broker runs when the TLS is enabled.

  • Open Bevywise/MQTTRoute/conf folder
  • In that, open “broker.conf” file. [ If you are a Windows user, you can either use a note pad or sublime to open the file ]
  • In “broker.conf” file, specify the port number in
  • TLS_PORT_NO = 8883. By default, it takes the value of 8883
  • Save the file and start running the MQTT broker.

Bevywise MQTTBroker User Interface

Sign-in Page

This page helps users to log in to the MQTT broker user interface securely. Below username and password are the default credentials to sign-in to the MQTT broker user interface.

  • Username – admin
  • Password – admin

Users can also change the username and password via the user interface based on their needs. To change the credentials, follow the below steps:

  • Login to the MQTT broker user interface using the above default credentials.
  • Click the user icon on the top left corner and select Change Password.
  • In the change password window, give your old and new password and save it.
To logout
  • In the MQTT broker user interface, click the user icon on the top right corner and select Logout.

Dashboard

The dashboard provides a quick snapshot of the latest happenings in the broker. It shows the status of the broker like count of messages in the last 30 seconds, Active topics, currently connected devices and uptime, disconnected device details. It also shows the recent activities like the Last 5 MQTT Clients connected and the time when it is connected, Published MQTT Message, the Last 5 errors occurred while connecting the device and topic, Disconnections, and Active subscribers.

Device details

The device details tab contains the list of devices that are connected to your MQTT Broker from the start of the broker. When you choose a single device, the right side of the tab provides details like device name, WILL topics and messages, and the time when it is connected. You can also get the published topics and messages as well as the subscribed topics. The Message Logs lets you know the list of messages from the clients and the topic discussed with the clients. In addition to that, the Subscribed device had an option called “Instant Command”, which is used to send a message or payload manually to the subscribed topic.

Topics

This tab provides details about all published and subscriber topics individually. It provides

  • Total published message count of individual topic
  • List of the device which published or subscribed to that topic
  • Individual topic status and time stamp

Rule Engine

The Rules are the first step to building intelligence to the broker. You will be able to customize the broker to send a different messages to the different clients based on the messages received by the broker. The rules can be defined based on the following conditions.

  • Client & Topic – Rule data contains Client name & topic
  • Topic & Message – Rule data contains Topic & Message
  • Client & Topic & Message – Rule data contains Client name, topic & message
  • Timer Rule – Send a message to the topic based on the give date and time

You can also add new rules and edit the existing rule. Based on the rule type selected, provide the details accordingly.

The messages can be transformed based on conditions like greater than, less than, equal to and not equal to. The messages received will be compared against these operands. You can also send the message as received for another topic.

MQTT Clients

Now Bevywise MQTTBroker is ready to connect your edge devices. Based on your configuration you have either connect without or with authentication. You can connect any standard MQTT Client that supports MQTT V3.1. You can also download our prebuilt libraries for the different OS to connect.

  1. Macintosh
  2. Linux
  3.  Windows 32-bit
  4.  Windows 64-bit
  5.  ESPClient

The MQTTRoute also has some examples to connect to the Broker inside the Bevywise/MQTTRoute/examples folder. 

Authentication

Add and remove username and password for Authentication.

To add authentication:

  • Click the + icon on the top left corner
  • Add Username and Password in the pop window and click save.

To delete authentication:

  • Click x icon next to the added username and password to delete authentication credentials.

Error Log

The Error Log tab contains a list of errors that occur while connecting a device to Bevywise MQTTBroker. The Below list helps you to identify the reason for the error.

ERRORREASON
Server busyServer busy, number of socket connection exceeded Server physical limit reached
Unknown ClientClient details are not given properly. Invalid Client details provided
Client id NullClient id Null, Connection entry restricted Client Identifier is NULL
Connection RefusedSame client id already found, try to connect with another client id Reusing an existing Client Identifier not allowed
Invalid CredentialUsername or password wrong. Connect with the correct user credential. Invalid Authentication Details Provided
Ping Response FailedDevice went offline. TCP Timeout occurred.
SSL AcceptError while establishing a secure connection. Invalid SSL Certificate or Connection
Protocol Not SupportedInvalid Protocol. The Received message is not in proper MQTT Format
Socket ClosedServer is busy
Device DisconnectedUnexpectedly device disconnected

Advanced Data Storage

MQTTRoute supports the storage of data in SQLite by default. But, for industrial production and development, SQLite is not efficient. For that case, you can change the storage configuration to MySQL. Also, for powerful visualization and analysis of data, you can store the data in Elastic Search or any other document-based Big Data engine using a custom implementation

The options can be configured using the data_store.conf file inside the conf folder.

[PERSISTENCE]
PERSISTENCE_ENABLED = TRUE

[CONFIG]
DB_SERVER= MSSQL
# SQLITE || MYSQL || MSSQL
# DB details for the SQLite

[SQLITE]
SQLITE_DB = bevywise

# DB details for the MYSQL. The DB will be created automatically in the Mysql Server

[MYSQL]
DBHOST =127.0.0.1
DBPORT = 3306
MYSQL_DB = bevywise
MYSQL_USER = root
MYSQL_PASSWORD =

# DB details for the MSSQL. The DB will be created automatically in the MSSQL Server

[MSSQL]
DRIVER =ODBC Driver 13 for SQL Server
SERVER_NAME = < Instance Name >
DBPORT = 1434
MSSQL_DB = bevywise
MSSQL_USER = sa
MSSQL_PASSWORD =

PERSISTENCE_ENABLED – When setting as TRUE, this will store the data either in SQLite or MySQL based on the DB_SERVER value. When set as false, it will not store data and the UI will not be accessible.

DB_SERVER – Specify whether the server needs to store data in MySQL or SQLite. when set as SQLLite, the data will be stored inside the data folder in the name of the file specified for SQLITE_DB

DBPORT – Port number of the MySQL. The default port will be 3306.

MYSQL_DB – The DB where you want to store the data inside MySQL.

MYSQL_USER – The username to be provided for the connection.

MYSQL_PASSWORD – The password to be provided for the connection.

MySQL/MSSQL configuration

To connect MQTTBroker and MySQL/MSSQL, follow the below steps:

For Linux and Mac user:
  • Open Terminal and go to ./Bevywise/MQTTRoute/bin
  • Run “sh installer.sh”, this file will install all dependence for MySQL and MSSQL.
  • Install MySQL 5.7 server or higher/MSSQL server 2013 or higher.
  • Go to ./Bevywise/MQTTRoute/conf and data_store.conf
  • In data_store.conf change as follows

MySQL

  • DB_SERVER = MYSQL
  • MYSQL_USER= < username >
  • MYSQL_PASSWORD = < Password >

MSSQL

  • DB_SERVER = MSSQL
  • DRIVER = ODBC Driver 13 for SQL Server
  • If ODBC driver 17 is installed, just change only 13 as 17. Do not change other text
  • To check whether ODBC driver install or not, go to control panel > Program and features > see ODBC 13 or 17 driver
  • If ODBC driver is not installed, download and install
  • SERVER_NAME = < instance name >
  • DBPORT = 1434 < mssql port >
  • MSSQL_USER = sa
  • MSSQL_PASSWORD = < mssql password >

For Windows/Windows server users:

  • From the desktop, right-click My Computer.
  • Choose Properties from the context menu.
  • Click the Advanced system settings link.
  • Click Environment Variables. In the section System Variables, find the PATH environment variable and select it. Click Edit. If the PATH environment variable does not exist, click New.
  • In the Edit System Variable (or New System Variable) window, specify the path where wget.exe located. Click OK. Close all remaining windows by clicking OK.
  • Open cmd and go to ./Bevywise/MQTTRoute/bin
  • Type installer.bat and hit enter, this file will install all dependence which required to establish the connection between MQTTBroker and MySQL
  • Dependency installed after running “installer.bat” file

                  1. Python 2.7

                  2. Pip 2.7

                  3. Mysql-connector-python

                  4. MSSQL-connector-python

Note: The above dependencies will be skipped if it already installed on PC.

  • Install MySQL 5.7 server or higher/MSSQL server 2013 or higher.
  • Go to ./Bevywise/MQTTRoute/conf and data_store.conf
  • In data_store.conf change as follows

MySQL

         DB_SERVER = MYSQL

         MYSQL_USER= < username >

         MYSQL_PASSWORD = < Password >

MSSQL

         DB_SERVER = MSSQL

         DRIVER = ODBC Driver 13 for SQL Server

  • If ODBC driver 17 is installed, just change only 13 as 17. Do not change other text
  • To check whether ODBC driver install or not, go to control panel > Program and features > see ODBC 13 or 17 driver
  • If ODBC driver is not installed, download and install

          SERVER_NAME = < instance name >

          DBPORT = 1434 < mssql port >

          MSSQL_USER = sa

          MSSQL_PASSWORD = < mssql password >

Note: Please don’t use XAMPP or MAMP for MySQL.

Python installation in windows

Once you run the installer.bat file, python2.7 will automatically download and the installation will start.[Python the installation will skip, if it was already installed]

Follow the below steps to install python2.7:

  • At first, you can see the following window will show up. In that, select the first option and click next
  • The next window will ask you about the path where you want python to be installed. Please leave this as default[C:\Python27\] and click Next.
  • Scroll down and click “Add python exe to path” and select “Will be installed on the local hard drive”. This will automatically set python as an Environmental variable. Click Next.
  • Once the above step is completed, the installation of the Python 2.7 will start on your Windows 7 machine.
  • When the setup is close to the finish, just click the Finish button as shown below.

Extendability

The features of MQTT Route is provided with certain extensions to make it flexible for users. You can customize it based on your needs. 

Custom Storage Configuration

MQTT Broker has an option called Custom storage to store data in elastic and other big data engines to store data

data_store.conf

[CUSTOM STORAGE]

[DATASTORE]
CUSTOMSTORAGE= DISABLED
# ENABLED || DISABLED
DATASTORE= CUSTOM
# ELASTIC || CUSTOM

[ELASTIC]
HOSTNAME = 127.0.0.1
PORT 9200
INDEX_NAME = mqtt
BULK_INSERT_TIMING = 2

[CUSTOM]
INTERCEPT_FILEPATH =./../extensions/custom_store.py

To configure, you must enable the CUSTOM STORAGE in data_store.conf file.

How to enable custom storage option

  • Open Bevywise/MQTTRoute/conf folder
  • In that, open data_store.conf file. [ If you are a Windows user, you can either use a note pad or sublime to open the file ]
  • In data_store.conf file, enable custom storage field. By default it takes the value as DISABLED
  • CUSTOMSTORAGE = ENABLED
  • Save the file and start running the MQTT broker.
  • If Custom Storage is enabled, the data will be sent to the document data store besides the MySQL/SQLite Storage.

How to choose data store

MQTTRoute has an option to store data to Elastic by default. It has an extension wherein you can hook the received payload and store the data in to any of your analytics / big data engine. If you are planning for storing the data in your own engine, you need to use the data_store.conf to configure your storage.

To select Elastic

  • Open Bevywise/MQTTRoute/conf folder
  • In that, open data_store.conf file. [ If you are a Windows user, you can either use a note pad or sublime to open the file ]
  • In data_store.conf file, specify Elastic in Data store field.
  • DATASTORE = ELASTIC
  • Save the file and start running the MQTT broker.

To select custom option

  • Open Bevywise/MQTTRoute/conf folder
  • In that, open data_store.conf file. [ If you are a Windows user, you can either use a note pad or sublime to open the file ]
  • In data_store.conf file, specify Custom in Data store field.
  • DATASTORE = CUSTOM
  • Save the file and start running the MQTT broker.

How to check Host name

HOSTNAME specifies the hostname of the datastore you are using to store data. If you are using Elastic as a custom data store, then the hostname of Elastic search will be mentioned.

For Example,

  • In data_store.conf file
  • HOSTNAME = 127.0.0.1

How to check port of the data store

PORT specifies the port of the chosen data store. If you are using Elastic as a custom data store, the port of the elastic server will be mentioned.

For Example,

  • In data_store.conf file
  • PORT = 9200

By default the port is 9200

How to check Index name

PORT specifies the port of the chosen data store. If you are using Elastic as a custom data store, the port of the elastic server will be mentioned.

For Example,

  • In data_store.conf file
  • INDEX_NAME = mqtt

Bulk Insert Timing

Bulk insert refers to the method provided by a database management system to load multiple rows of data into a database table. In accordance with the BULK INSERT statement, bulk insert allows importing external data files into data base server. BULK_INSERT_TIMING refers to the time in which the bulk data is imported.

For Example,

  • In data_store.conf file
  • BULK_INSERT_TIMING = 2

For custom implementation, You can implement the above method in your own file and then specify the path here: INTERCEPT_FILEPATH.

Note: Currently we have custom plugins to store data in MongoDB, elastic search and Redis. We can also customize the MQTT broker to data or payload to any big data engines based on customer needs. Contact us for other customization.

Custom Data Store

AI / ML plays a major role in any IoT Implementation. So the data received from the different sensors need to be modeled and stored to any BIG data engine for further analysis and decision making. MQTT Route provides an option called the custom store to receive data at the back end to be stored as needed.

Custom Store implementation is used to hook the received payload from MQTTBroker and store the payload in any of your analytics / big data engine. To configure, you must enable the CUSTOM STORAGE in data_store.conf.

You need to enable CUSTOM STORAGE to receive the data of the message received from the devices into a python call back handle_Received_Payload (data) . the method need to be implemented in the python file specified in the INTERCEPT_FILEPATH.

The data will be passed in a JSON format with the following keys – ‘sender’,’topic’, ‘message’, ‘unixtime’, ‘timestamp’

Your implementation should receive the data and store it and return the method. We advice you to just store the data or hand over the data to a stream analysis and return the method handle. Below is the custom_store.py file

extensions/custom_store.py

# Importing the custom class into the handler
from customimpl import DataReceiver
datasend = DataReceiver()

def handle_Received_Payload(data):
      # Write your code here. Use your connection object to
      # Send data to your data store

       print “print in the handle_received_payload” , data
       result = datasend.receive_data(data)
      # if result is none then write failed

def handle_Sent_Payload(data):
      # Write your code here. Use your connection object to
      # Send data to your data store

       print “print in the handle_sent_payload” , data
       result = datasend.sent_data(data)

Custom UI server

UI custom server provides an option to customize the user interface. You can alter the code in Custom_ui_server.py  file as you need to customize it. You will be able to configure your dashboard to view device data as per your needs. You can add your own requirements, device details or notifications to the user interface as required. The UI custom server will help you customize the UI of the MQTTRoute by adding your own code on the server-side. Add your new functionality using the URL and the corresponding method. These URLs can be invoked from your User Interface for manipulating data.

custom_ui_server.py

#
# Configure your additional URLs here.
# The default URLs are currently used for the UI.
# Please don’t remove them, if you are building it over the same UI.
#

def custom_urls( ):

      urllist={
          “AUTHENTICATION” : ‘DISABLE’,
          “urls” : [{“/extend/url1” : method},
          {“/extend/url2”:method1},
          {“/extend/url3”:method2}]
      }
      return urllist

# write your url function codes in the following methods
def method( ):
      return ( “BEVYWISE NETWORKS” )

def method1( ):
      return ( “BEVYWISE NETWORKS” )

def method2( ):
      return ( “BEVYWISE NETWORKS” )

Custom Scheduler

The Scheduler allows easier scheduling of tasks to be broadcasted. Scheduler can be configurable by the user using the custom_scheduler.py file. The Custom Scheduler will help you create your own schedule in MQTTRoute by adding your own code on the server-side. SQL connector will be provided as cursor global variable for querying the Database & Elastic Search connector for querying Elastic if you have enabled custom storage option.

custom_scheduler.py

def schedule_conf( ):

# ENABLE/DISABLE YOUR SCHEDULE
#Add your schedule time in MINUTES in ‘OnceIn’
#Add your method to call on schedule in ‘methodtocall’

        schedules={}

        schedules={
        ‘STATUS’ : ‘DISABLE’,
        ‘SCHEDULES’ : [
        {‘OnceIn’ : 1,‘methodtocall’ : oneminschedule },
        {‘OnceIn’ : 5,‘methodtocall’ : fiveminschedule } ] }

        return schedules

#
# SQL Connector. It will be sqlite / mssql / mysql cursor based
# on your configuration in db.conf
# Please construct your queries accordingly.
global db_cursor
#
#Client object. It used to send/publish message to any active clients
#Simply call the function with parameters like User_name, Client_id, Topic_name, Message, QOS,
global Client_obj

#
# elasstic_search cursor.
#
global elastic_search
# Called on the initial call to set the SQL Connector

global web_socket
# Web_socket
def setsqlconnector ( conf ):
      global db_cursor
      db_cursor=conf [ “sql” ]

def setelasticconnector ( conf ):
      global elastic_search
      elastic_search=conf [ “elastic” ]
def setwebsocketport ( conf ):
      global web_socket
      web_socket=conf [ “websocket” ]
def setclientobj ( obj ):
        global Client_obj
        Client_obj=obj [ ‘Client_obj’ ]

def oneminschedule ( ):
      pass
      #Write your code here
      #print “extension print”

def fiveminschedule ( ):
      pass
      #Write your code here
      #print “5 mins extend”

RESTful API

The Custom data store helps you receive, process and store data in your own big data store. This does not complete the cycle of Broker integration. RESTful API help you call the broker for managing any specific device or device as a whole. The restful API will also help in querying the connected devices list and related APIs to manage the broker as well as the edge devices.

Refer to the API document for the details of the methods.

WILL and Retained Messages

MQTT broker supports WILL and Retained messages. The client can configure to WILL when connecting with the broker. You can receive Retain messages by configuring to the Retain bit. WILL message lets you publish messages to clients in case of an ungraceful disconnection. Retained messages are sent to new subscribers on a particular topic. The broker will process the request and publish the messages to the configured clients.

QoS Support

MQTT broker supports multiple QoS levels specified by MQTT Protocol. MQTT Clients can subscribe to any topic with any QoS levels ‘0 – At most once’, ‘1 – At least once’ or ‘2 – Exactly once’. The broker will check for the QoS configuration when the client subscribes. Default QoS is ‘0’. ,/p>

QoS 0 – At most once

The Sender sends the message only once. The receiver of the message will not acknowledge it and the sender will not check for the delivery status of the message

QoS 1 – At least once

Sender guarantees message delivery. The Sender sends a message once and will wait for the acknowledgment from the receiver. The Sender will send the message until it receives the acknowledgment.

QoS 2 – Exactly once

Message sent will be acknowledged each time by the receiver. The sender will send the publish message. After receiving an acknowledgment from the receiver, The sender will send the instruction to release the published message. The receiver will send an acknowledgment for this message also.

Running Broker as Service

MQTTBroker as a Service in Linux

To run the MQTTBroker as service we need the Monit version 5.25. Monit is an open source dynamic monitoring tool for Linux systems which is used for monitoring and managing system processes. And also, it performs automatic maintenance or repair of a particular process (i.e., restarting the service) and execute significant informal actions in error conditions whenever necessary.

Download & Install Monit

$ sudo apt install monit

$ sudo systemctl disable monit

$ wget https://mmonit.com/monit/dist/binary/5.25.2/monit-5.25.2-linux-x64.tar.gz

Extract the archive using the command below

$ tar -xvzf < Downloaded file > (For example – $ tar -xvzf monit-5.25.2-linux-x64.tar.gz)

Copy monitrc file and paste in below location

$ sudo cp monit-5.25.2-linux-x64/monitrc /etc/

$ sudo chmod 700 /etc/monitrc

Enable Monit HTTP interface

Enable the HTTP interface by uncommenting the following lines in /etc/monitrc file.

set httpd port 2812 and
use address localhost # only accept connection from localhost (drop if you use M/Monit)
allow localhost # allow localhost to connect to the server and
allow admin:monit # require user ‘admin’ with password ‘monit’

If you want you can change admin:monit with username and password you want to use.

Start Monit

$ cd monit-5.25.2/bin/

$ sudo pkill -9 monit

$ sudo ./monit

Open Monit UI using the below URL in your web browser

http://localhost:2812

monit-web-interface

MQTTBroker as a Service in Windows/Windows server

 

Set the environmental variable for runbroker.bat and MQTTRoute.exe

  • Right-click My computer and select “Properties”.
  • Click “Advanced System Variable” from the left side panel.
  • In “System Properties” pop-up click the “Advance” tab and click the “Environmental Variable” button on the bottom.
  • In “Environmental Variable”, select Path from system variables and click Edit.
  • In that add
  1.  runbroker.bat path[ installation path/Bevywise/MQTTRoute/bin]
  2.  MQTTRoute.exe path[ installation path/Bevywise/MQTTRoute]
  3.  Click Ok.
  • Next, open the “Task Scheduler”
  • In the Task scheduler window, right-click the “Task Scheduler” on the left pane and select “Create Basic Task..”.
  • In “Create Basic Task” wizard,
  1. First, give a Name and Description for the Task and click next
  2. Select “When the computer starts” and click next
  3. Select “Start a program” and click next.
  4. In Program/Script, click Browse and specify runbroker.bat path[ installation path/Bevywise/MQTTRoute/bin]. Click next
  5. Select the “Open the Properties dialog box for this task” checkbox and click Finish.
  6. Next, the “In Properties” dialog box will open. In that select “General” tab and select “Run whether the user is logged on or not”. Also, enable “Run with highest privileges” checkbox.
  7. Next, select “Condition” and uncheck all the checkboxes.
  8. Select “Setting”, enable “If the task fails, start every:” checkbox and select the time interval [default min time is one min] and uncheck all other checkboxes.
  9. Next click ok to save the properties.
  • Once you install the MQTTBroker will set to “startup program”, which means it will start when the PC starts. So we must remove MQTTBroker form “Startup program”

For Windows 7 or higher:

  • Click start and search “System Configuration”
  • In that wizard, under “startup”, click ” Bevywise MQTTRoute” and disable it.

For Windows Server 2012R2 or higher:

  • Press “windowskey+r” to open the run window 
  • In that type “shell:common startup” and click OK 
  • Now the Startup window will open. In that Delete the Bevywise MQTTBroker and close the windows. 
  • Next Restart the PC. Now the Broker will run as a service via Task scheduler.
  • To check:
  1. In the command prompt, type “netstat -a” and press enter. 
  2. In output, you can see 0.0.0.0:1883, 0.0.0.0:8080, 0.0.0.0:8081 port are running. [1883 -MQTTBroker, 8080 – MQTTBroker UI, 8081:Client connection].

MQTT Gateway

The MQTT Gateway acts as an intermediate agent between the Sensors and the MQTT Broker. The MQTT Gateway has inbuilt functionality to discover all the sensors that run around the gateway. The gateway advertises itself and the Clients will be able to search for the gateway in return.

The gateway can be started in two modes

Aggregated Gateway – The gateway will make only one connection with the central MQTT Broker and will aggregate all the messages from the individual sensors and send it to the broker via the single connection. This will reduce the load on the Central Broker.

Transparent Gateway – This gateway will just act as a forwarding agent and each sensor will be individually connected to the central broker.

The gateway supports the accumulation of messages when the client goes for a sleep state and sends all the messages when the client comes back.

Note: Without Bluetooth, MQTTGateway will not work. So, enable Bluetooth in your PC and follow the below steps.

To start MQTTGateway:

Without starting MQTTBroker, Gateway will not start. So, start the Gateway after along with the MQTTBroker.

For Windows:

  • Double click the “rungateway.bat” file inside the Bevywise/MQTTRoute/bin folder.

(or)

  • Third, Open cmd and go to Bevywise/MQTTBroker/bin folder. Next, type “rungateway.bat” and hit enter.

To start MQTTGateway in other OS:

  • Open the terminal and go to Bevywise/MQTTRoute/bin
  • Type “sh runbroker.sh” and hit enter.

Configuring Bevywise MQTT Gateway 

The Gateway can be configured using the gateway.conf file inside the conf folder.

conf/gateway.conf

[SERVER_CONFIG]
PGATEWAY_NAME = “gateway1”
SERVER_TLS_ENABLED = FALSE

# True to enable TLS and listen SERVER_TLS_PORT & False to disable TLS and listen SERVER_PORT.

SERVER_IP = 127.0.0.1
SERVER_PORT = 1883
SERVER_TLS_PORT = 8883

# TLS_PORT must be 88xx.
SERVER_AUTHENTICATION_ENABLED = FALSE
USERNAME = Hello
PASSWORD = hello

# Gateway config to MQTT Client.

[GW_MQTT_LISTEN_CONFIG]
GW_MQTT_ENABLED = TRUE

# True to listen MQTT Client & False to disable MQTT Client.
GW_TLS_ENABLED = FALSE

# True to listen MQTT Client in secured channel.
GW_MQTT_PORT = 1884

# Gateway config to MQTTSN Client.

[MQTT_SN_CONFIG]
GW_MQTT_SN_ENABLED = TRUE

# True to listen MQTTSN Client & False to disable MQTTSN Client.
GATEWAY_TYPE = TRANSPARENT

#AGGREGATED || TRANSPARENT

# multicast Address for Gateway
GW_GROUP_ADDR = 224.2.2.1
GW_GROUP_PORT = 1883

# multicast Address for SN Clients
SN_GROUP_PORT = 1884
SN_GROUP_ADDR = 224.3.3.1
GW_PATH_TO_PREDEF_TOPIC = ./conf/predefined_topics.txt
# set the predefined Topic name and id in the file.
# Format:

Localization

You can now make the MQTT Broker show details on the User Interface in your language for all your employees and technicians. We support a few languages by default. It is easy to add your text to the localization.js file to make it easier for your team. The following steps help you do it.

  • Identify language code – Visit the language codes page to understand the code used for your language.
  • Open the localization.js inside the folder Bevywise/MQTTRoute/web/build/js.
  • Copy the English text below the “en” code which is at the starting of the file and paste it at the end. Change the “en” code to your web browser language code. Provide a meaningful text in your language for the corresponding English text on the right side of the: separator.
  • Once you have done save the file and restart the broker. Now the UI will be changed to your language.

Feel free to send us the translated file, so that we can distribute the changes you have done to your national people in your name. Send to [email protected]

Package Structure

This gives you the details about the MQTTRoute Product Package. When you unzip the file, a folder Bevywise will be created. The contents of the Broker are in Bevywise/MQTT_Broker location.

bin/

This folder contains the executable file required to run Bevywise MQTTBroker. The runbroker.sh file runs the broker using the python executable file.

Certificate/

This folder contains a secure SSL/TLS certificate. The client and server contain a common CA certificate root.crt file which is the Certificate Authority to verify the clients and the server. client/ will have the client.crt certificate file and client.key file for the certificate. server/ will have a server.crt certificate file and server.key key file for the certificate.

conf/

In this folder, the configuration file for the broker is stored. The properties like Broker Port, TLS Port, Enable/Disable TLS and Authentication of the user can be configured using the broker.conf file.

data/

This folder contains the SQLite database that stores all the details of the broker. When the broker runs, the database is created.

lib/

This folder contains the core libraries of Bevywise MQTTBoker.

license/

This folder contains the open source license agreement and license file of the MQTTBroker libraries.

ui/

This folder contains the required files for the User Interface. You can see the user interface from your browser using 127.0.0.1:8080.

README

A text file which guides the user step by step to run the Bevywise MQTTBroker.

Have More Questions?

We are with all ears waiting to hear from you. Post us with your questions and feedback.

Write to us