This code connects to an MQTT broker to publish and subscribe to topics to receive messages.
pip install -r requirements.txtThis file includes:
paho-mqtt==1.6.1
python-decouple==3.8
- You need a Broker MQTT running. I recommend Mosquitto.
Ex (Do not need to do):
mosquitto -v: Running Broker;mosquitto mosquitto_sub -h BROKER_IP -p PORT -t TOPIC: Subscribe in topic.mosquitto_pub -h BROKER_IP -p PORT -t TOPIC -m MESSAGE: Publish "MESSAGE" in topic.
- Duplicate the
.env-examplefile and configure it; - Edit name
.env-exampleto.env; - Execute
MqttClient.py.
python3 MqttClient.py
