Mosquitto For IOT Project Part I
Posted By : Tarun Singhal | 21-Jan-2018
Mosquitto For IOT Project Part - I
Mosquitto is
- It is made for non-TCP/IP communication between the IoT gateways and cloud platforms.
- Mosquitto is implemented on MQTT Protocol. MQTT is a message broker complatible for IOT implementations.
- It supports most of the hardware such as phones, embedded computers or microcontrollers like the Arduino, Rasberry
pi . - It can be installed on Linux, Mac
and Windows also.
Installation!
Mosquitto is available through the main repository.
For ubuntu
sudo apt-get install mosquitto
Configuration!
Enable Logging
vim /etc/mosquitto/mosquito.conf
log_dest <destinations>
Enter the log’s location in the destination part.
log_timestamp true
Enable the log timestamp.
log_type <types>
You can define the level of logging.
available levels are
- debug
- error
- warning
- notice
- information
- subscribe
- unsubscribe
websockets - none
- all
Enable Persistence
In production Don’t forget to enable the persistence.
If Persistence is On/True then data will be written on the disk in mosquitto.db
persistencen [True/False]
persistence_file <file name>
Here you can define the database name
persistence_location <path>
Here one can define the location of the database.
Security
Steps to be taken to
allow_anonymous [ true | false ]
If enable client need to provide the username and password to connect to the broker.
use ssl for more security.
To enable the
certfile <file path>
cafile <file path>
keyfile <file path>
tls_version <version>
Enable Authentication.
password_file <file path>
Here you can define the path of file having username and password
To Create a Hashed file.
- create a file named password.conf
vim password.conf
Now Enter username and password in the key value format
Username1:Secret1
Username:Secret2
- But it is in plain text to make this file compatible
for mosquitto , update this file intoHash format. - To do so use command
mosquitto_passwd -U password.conf
After Update, your file looks like
Username1:$6$SPqxUIaJeV7c8we0$U/rF4YKOwDh2aJ97ZfP3q5HXqeBJkTmPDpwViPx1MVFNeN5Vib2ZNCbn8H542oc8A05szx+IcE3yXoxkeUwmjg==
Username:$6$i/nCIr8NuV9LKmoU$w8HxqwY5zyi7ae/Ofy9hhu1CxvsCe1cdITYkLsWofp6jnYpZhXIgTsSoAxZi/JJNCUfEXkZgBEHVVZK98w6cTw==
- U is to update the file into Hash Format.
- Now, when you have multiple
user and you need to give distributed permission to each of them. - There is an ACL option for that.
acl_file <file path>
In this
So We can define READ/WRITE permission on each
user username
topic <permission> <TOPIC>
Example
user Username1
topic read /bus
topic write /train
As This Article is divided into Two or more parts. We had enough for this part. In the Next
Tunnig ofmosquitto .- QOS levels.
- Acl file in Deep.
- What is
Topics. - Websocket Integration with
mosquitto . - How client will connect to
broker .
Thanks, Hope this will help you in any way.
Cookies are important to the proper functioning of a site. To improve your experience, we use cookies to remember log-in details and provide secure log-in, collect statistics to optimize site functionality, and deliver content tailored to your interests. Click Agree and Proceed to accept cookies and go directly to the site or click on View Cookie Settings to see detailed descriptions of the types of cookies and choose whether to accept certain cookies while on the site.
About Author
Tarun Singhal
Tarun is a RedHat Certified System Administrator. He is very keen to learn new technologies. He has good command over tools like Ansible, Gitlab-CI etc.