Source code and slides for the mid semester seminar submitted for my wireless networks course.
MQTT is a client server publish/subscribe messaging transport protocol, ideal for constrained environments such as for communication in Machine to Machine (M2M) and Internet of Things (IoT) contexts.
Eclipse Mosquitto is an open source MQTT broker and one of the popular choices for a broker.
I have built an example application using Mosquitto and Paho's python client library.
In terms of functionality, I have:
- Created subclasses of
mqtt.Client
- does not seem to be preferred way as official documentation it has only one such example. - Used
mosquitto_passwd
to manage authentication. - Used Topics, QoS Levels, Retained Messages and Last Will And Testatement.
For some reason, the auto-generated client ids were not defined - MQTT specfication specifies that broker must asssign a client id if client id of zero bytes is sent with CONNECT packet. I need to check if the same problem when I don't subclass it. One other alternative could be generate client id on basis of pid (just like topics), and pass it to the broker.
-
Install Mosquitto as an application or run it as an docker container (see slides 4-6 for more):
-
Create a python virtualenv:
python3 -m venv pyenv
- Activate the virtual environment (the exact command will depend on your OS):
source pyenv/bin/activate
- Install the required packages:
pip install -r requirements.txt
- Start the docker container (if not done already):
docker start mosquitto
- Run the producer and consumer scripts:
python rng_producer.py
python rng_consumer.py