Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/farshidtz/dht-mqtt
Publish DHT sensor readings to MQTT broker
https://github.com/farshidtz/dht-mqtt
dht11 dht22 mqtt raspberrypi
Last synced: about 1 month ago
JSON representation
Publish DHT sensor readings to MQTT broker
- Host: GitHub
- URL: https://github.com/farshidtz/dht-mqtt
- Owner: farshidtz
- License: mit
- Created: 2017-12-08T09:56:57.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2022-06-27T18:15:33.000Z (over 2 years ago)
- Last Synced: 2023-03-04T23:19:33.070Z (almost 2 years ago)
- Topics: dht11, dht22, mqtt, raspberrypi
- Language: Python
- Homepage:
- Size: 15.6 KB
- Stars: 1
- Watchers: 1
- Forks: 4
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# DHT-MQTT
Read humidity and temperature measurements from a DHT11/DHT22 sensor connected to a Raspberry Pi and publish them to an MQTT broker.It also supports the AM2302 sensor, which is the wired version of DHT22.
## Run as a service
Requirement: Python 3, pip### Install
Install the [CircuitPython-DHT](https://github.com/adafruit/Adafruit_CircuitPython_DHT) library:
```bash
pip3 install adafruit-circuitpython-dht paho-mqtt
sudo apt-get install libgpiod2
```### Configure and run as a service
1. Clone and enter the directory```bash
git clone xxx
cd dht-mqtt
```2. Create `config.env`
Copy from `config.env.example`.
Set the right values.
* `BROKER` (string) is the MQTT broker's host name or IP address
* `BROKER_PORT` (integer) is the MQTT broker's port
* `PIN` (integer) is the GPIO pin number that the sensor data wire port is connected to. The python board module can be used to list available pins on the board. Learn more [here](https://learn.adafruit.com/circuitpython-digital-inputs-and-outputs/board-pins).
* `SENSOR` (string) is the sensor type. It should be either of: DHT11, DHT22, DHT213. Run to test:
```
./run.sh
```4. Turn into a service
We use the `dht-mqtt.service` file to create the service.
In the service file, the path for the `run.sh` script is set to `/home/pi/dht-mqtt/run.sh`.
Modify the file to have the correct path and user.Make a symbolic link to the service file:
```
sudo ln -s /home/pi/dht-mqtt/dht-mqtt.service /lib/systemd/system/dht-mqtt.service
```Load the service file, enable (start on boot), and start now:
```bash
sudo systemctl daemon-reload
sudo systemctl enable --now dht-mqtt
```Check the logs:
```bash
journalctl -u dht-mqtt -n 100 -f
```Use `systemctl restart dht-mqtt` to load new configurations.
## Run in a Docker container
WIP```
docker run --privileged farshidtz/adafruit_dht [11|22|2302] GPIOpin#
```For example to read from a DHT22 attached to GPIO4:
```
docker run --privileged farshidtz/adafruit_dht 22 4```
## Build Locally
```
docker build -t my_dht .
```