---
# System prepended metadata

title: MQTT Mosquitto
tags: [IoT over Kubernetes]

---

# MQTT Mosquitto

###### tags: `IoT over Kubernetes`

reference : [Here](https://linoxide.com/tools/setup-mosquitto-mqtt-server-ubuntu-16-04/), [Here](https://lms.onnocenter.or.id/wiki/index.php/MQTT:_install_di_Ubuntu_16.04#Setup_MQTT-Spy_dan_connnecting)


Mosquitto MQTT Server is a message broker which works over MQTT protocol. MQTT is lightweight messaging protocol that is ISO standard for use on top of TCP/IP protocol.  It is mostly used for communicating with Internet of Things devices. We are going to install Mosquitto on a Ubuntu 16.04 server and we are going to send messages from MQTT-spy software. Mosquitto is an Eclipse project and it is distributed under EDL license.

## Compiling Mosquitto MQTT server from source

Installing apps dependencies:

	sudo su
![](https://i.imgur.com/3J275RB.png)
(Optional) 

	locale-gen id_ID.UTF-8
	apt install build-essential libwrap0-dev libssl-dev libc-ares-dev uuid-dev xsltproc
![](https://i.imgur.com/RaSYNx7.png)

Install finished.
![](https://i.imgur.com/3LTeYi7.png)

adding moquitto user, because by default `mosquitto` run as non-root

	adduser mosquitto
![](https://i.imgur.com/eDMj0Gl.png)

Enter password and I just assign my fullname for mosquitto (The other information could be optional)
![](https://i.imgur.com/L8Y9G1y.png)

For user mosquitto privileges add this command (aka sudo rights):

	usermod -aG sudo mosquitto
	
![](https://i.imgur.com/9iKqG8l.png)

So as we can see if we use this command:

	su mosquitto
	cd
![](https://i.imgur.com/J1dyvpn.png)
We will come to the mosquitto bash.

Download Mosquitto source code, latest version is 1.4.9

	wget https://mosquitto.org/files/source/mosquitto-1.5.gz
	tar xvzf mosquitto-1.5.tar.gz
	cd mosquitto-1.5/
	make && sudo make install
![](https://i.imgur.com/P59Z0h4.png)
Extract:
![](https://i.imgur.com/OPvLVO6.png)
![](https://i.imgur.com/M55XprM.png)

as the previous 
![](https://i.imgur.com/4h74Nji.png)
![](https://i.imgur.com/UrtTG0b.png)
![](https://i.imgur.com/vL35VW6.png)
![](https://i.imgur.com/dKcoKk4.png)
![](https://i.imgur.com/G2BnTtL.png)
![](https://i.imgur.com/Y5pMqGV.png)

![](https://i.imgur.com/9e2yF2N.png)

![](https://i.imgur.com/tEsZ0VZ.png)

Solve: https://community.openenergymonitor.org/t/mosquitto-wont-start-on-boot-after-raspbian-and-emonsd-update/5588/19

![](https://i.imgur.com/AU09xiW.png)

	cd /usr/local/src
	wget https://github.com/kamilfb/mqtt-spy/releases/download/mqtt-spy_v0.5.4/mqtt-spy-0.5.4-jar-with-dependencies.jar
	
#### After that, Download jdk 8 dan jre 8

Installation Here:
https://stackoverflow.com/questions/55920389/e-package-oracle-java8-installer-has-no-installation-candidate

and pick the first java 1.8 with:
	
	sudo update-alternatives --config java
	
And type 0.

After java installed, we can now run the mqtt-spy:

	sudo java -jar mqtt-spy-0.5.4-jar-with-dependencies.jar
	
![](https://i.imgur.com/xsGDKsJ.png)

## Send Messages with MQTT
Step 1: click Connections tab > new connection or CTRL + N

![](https://i.imgur.com/rbtwzhC.png)
As we can see, we successfull to open it.

Step 2: add new IP server, for instance 192.168.1.11