Get Informed out of Data

Full width home advertisement



Post Page Advertisement [Top]

Mosquitto MQTT configuration for Owntracks in Raspberry pi 4

Mosquitto MQTT configuration for Owntracks in Raspberry pi 4

OwnTracks is an Open Source project which provides an iOS and an Android app with which your smartphone records its current location.

Mosquitto is an open-source message broker service that uses the MQTT protocol to send and receive messages, typically with IOT (Internet of Things) devices.

An MQTT broker(server) is a service to which MQTT clients connect. These clients publish data to specific topics and they can subscribe to one or more topics to receive messages. A topic is like an "address" for a particular message. 

Install Mosquitto:

Download the latest release of mosquitto listed here:

cd /home/mosquitto
tar xvzf mosquitto-X.X.X.tar.gz
cd mosquitto-X.X.X

Run make to compile and make install to install

make install

The broker is immediately started; stop it.

sudo /etc/init.d/mosquitto stop

To create a mosquitto user database, use 

sudo mosquitto_passwd -c /etc/mosquitto/passwd <username>.

Create the directory where persistence db files will be stored, change owner to mosquitto:

mkdir /var/lib/mosquitto/
chown mosquitto:mosquitto /var/lib/mosquitto/ -R

Create a config file by copying the example file:Run make to compile and make install to install

cp /etc/mosquitto/mosquitto.conf.example /etc/mosquitto/mosquitto.conf
editor /etc/mosquitto/mosquitto.conf

change the broker settings in /etc/mosquitto/mosquitto.conf as required for your application

port 1883
persistence_file mosquitto.db
log_dest syslog
log_dest stdout
log_dest topic
log_type error
log_type warning
log_type notice
log_type information
connection_messages true
log_timestamp true
allow_anonymous false
password_file /etc/mosquitto/passwd

Let's start testing it out,

To subscribe all topics enabled by owntracks run the following command on one terminal:

mosquitto_sub -h hostname -p 1883 -v -t 'owntracks/#'

In another terminal publish a test message:

mosquitto_pub -h hostname -p 1883 -t 'owntracks/test' -m 'hello world'

and in the first screen you'd see the topic name followed by a space and the message payload.

Now, on the Owntracks Android app set the MQTT connection via raspberry pi URL.

No comments:

Post a Comment

Bottom Ad [Post Page]