MQTT (MQ Telemetry Transport)
MQTT is a lightweight, publish-subscribe network protocol that transports messages between devices. The protocol usually runs over TCP/IP, however, any network protocol that provides ordered, lossless, bi-directional connections can support MQTT.
An MQTT broker is an intermediary entity that enables MQTT clients to communicate. Specifically, an MQTT broker receives messages published by clients, filters the messages by topic, and distributes them to subscribers.
sudo apt remove mosquitto
sudo apt remove mosquitto-clients
apt-get install mosquitto
apt-get install mosquitto-clients
192.168.1.4 (IP of Raspberry Pi)
Open a Terminal and type it...
mosquitto_sub -h 192.168.1.4 -t sample_topic_name
Open another Terminal and type it...
mosquitto_pub -h 192.168.1.4 -t sample_topic_name -m "Hi this is test message"
sudo mosquitto_passwd -c /etc/mosquitto/passwd your_username
192.168.1.4 (IP of Raspberry Pi)
Open a Terminal and type it...
mosquitto_sub -t "topic" -u "your_username" -P "your_password"
Open another Terminal and type it...
mosquitto_pub -t "topic" -m "message from mosquitto_pub client" -u "your_username" -P "your_password"
sudo systemctl status mosquitto
sudo systemctl start mosquitto
sudo systemctl restart mosquitto
sudo systemctl stop mosquitto
sudo nano /etc/mosquitto/mosquitto.conf
##### CONFIGURATIOS (AUTHENTICATION NOT NEEDED) ######
listener 1883
pid_file /var/run/mosquitto.pid
persistence true
persistence_location /var/lib/mosquitto/
log_dest file /var/log/mosquitto/mosquitto.log
include_dir /etc/mosquitto/conf.d
allow_anonymous true
................................................................................................
##### CONFIGURATIOS (NEED AUTHENTICATE) ######
listener 1883
#pid_file /var/run/mosquitto.pid
persistence true
persistence_location /var/lib/mosquitto/
log_dest file /var/log/mosquitto/mosquitto.log
include_dir /etc/mosquitto/conf.d
allow_anonymous false
password_file /etc/mosquitto/passwd