https://github.com/mazen-daghari/mqtt-pyqt6-dht11
This application integrates a DHT11 sensor, MQTT communication, and a PyQt6 graphical user interface (GUI). The DHT11 sensor reads temperature and humidity data, which is then published to an MQTT broker.
https://github.com/mazen-daghari/mqtt-pyqt6-dht11
arduino dht11 matplotlib mqtt pyqt6 python
Last synced: about 1 month ago
JSON representation
This application integrates a DHT11 sensor, MQTT communication, and a PyQt6 graphical user interface (GUI). The DHT11 sensor reads temperature and humidity data, which is then published to an MQTT broker.
- Host: GitHub
- URL: https://github.com/mazen-daghari/mqtt-pyqt6-dht11
- Owner: mazen-daghari
- License: mit
- Created: 2024-12-02T22:53:28.000Z (5 months ago)
- Default Branch: main
- Last Pushed: 2024-12-02T23:00:55.000Z (5 months ago)
- Last Synced: 2025-01-30T10:17:04.737Z (3 months ago)
- Topics: arduino, dht11, matplotlib, mqtt, pyqt6, python
- Language: Python
- Homepage:
- Size: 3.42 MB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# mqtt-pyqt6-dht11
This application integrates a DHT11 sensor, MQTT communication, and a PyQt6 graphical user interface (GUI). The DHT11 sensor reads temperature and humidity data, which is then published to an MQTT broker.
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------Let's dive into a detailed tutorial about MQTT and how it is used.
What is MQTT?
MQTT stands for Message Queuing Telemetry Transport. It is a lightweight messaging protocol designed for small sensors and mobile devices with low bandwidth. MQTT is ideal for Internet of Things (IoT) applications where devices need to communicate with each other efficiently.Key Concepts of MQTT
Publish/Subscribe Model:Publish: Devices (clients) send messages to a central server (broker) on specific topics.
Subscribe: Devices (clients) subscribe to topics to receive messages.
This model decouples the sender (publisher) and receiver (subscriber), allowing for flexible and scalable communication.
Broker:
The broker is the central server that receives all messages from the publishers and routes them to the appropriate subscribers.
Popular brokers include Mosquitto, HiveMQ, and EMQX.
Topics:
Topics are the way messages are categorized and routed.
They are represented as strings separated by slashes (e.g., home/temperature).
Topics are case-sensitive.
Messages:
Messages are the data sent by the publisher to the broker.
They can contain any type of data, such as sensor readings or commands.
How MQTT Works
Client Connection:Clients (devices) connect to the broker using a unique client ID.
The connection can be secured using SSL/TLS.
Publishing Messages:
A client publishes a message to a specific topic.
The broker receives the message and forwards it to all clients subscribed to that topic.
Subscribing to Topics:
A client subscribes to one or more topics.
The broker sends messages on those topics to the subscribed clients.
Quality of Service (QoS):
MQTT supports three levels of QoS to ensure message delivery:
QoS 0: At most once delivery.
QoS 1: At least once delivery.
QoS 2: Exactly once delivery.
Setting Up MQTT
Install an MQTT Broker:For example, you can install Mosquitto on your system. Follow the instructions on the Mosquitto download page.
Install MQTT Client Libraries:
For Python, you can use the paho-mqtt library:
sh
pip install paho-mqtt
Example: Using MQTT with Python
Publishing Messages:python
import paho.mqtt.client as mqttbroker = "broker.hivemq.com"
port = 1883
topic = "home/temperature"client = mqtt.Client("Publisher")
client.connect(broker, port)message = "25.5"
client.publish(topic, message)
client.disconnect()
Subscribing to Topics:python
import paho.mqtt.client as mqttbroker = "broker.hivemq.com"
port = 1883
topic = "home/temperature"def on_message(client, userdata, message):
print(f"Received message: {message.payload.decode()} on topic {message.topic}")client = mqtt.Client("Subscriber")
client.connect(broker, port)
client.subscribe(topic)
client.on_message = on_messageclient.loop_forever()
Use Cases of MQTT
Home Automation:Control lights, thermostats, and other devices.
Example: An ESP32 publishes temperature data to the broker, and a home automation system subscribes to this data to adjust the thermostat.
Industrial IoT:
Monitor and control industrial equipment.
Example: Sensors publish data about machine performance, and a central system subscribes to this data to monitor and control the machines.
Healthcare:
Monitor patient health data.
Example: Wearable devices publish health metrics, and healthcare providers subscribe to this data for real-time monitoring.
Conclusion
MQTT is a powerful and efficient protocol for IoT applications, enabling seamless communication between devices. By understanding its key concepts and how to implement it, you can build robust and scalable IoT systems.for further informations email me on :[email protected]