This application measures temperature and humidity with a DHT22/AM2302 sensor connected to the Raspberry Pi.
The sensor is read out with a Python script and the library Adafruit_CircuitPython_DHT. The measurement data is displayed in the console and can optionally be save to a database (MariaDB) and displayed on a web server.
- Raspberry Pi
- Raspberry Pi OS (previously called Raspbian), Version: 10 buster / 11 bullseye
- Sensor: DHT22 (AM2302) (Buy: int./de)
- optional: Docker & docker-compose
It use physical PIN7 = GPIO4 (D4) by default. You can now* change the GPIO Pin over a env-Variable (see below).
The other two cable of AM2302
are connect to 3V (or 5V) and Ground.
# Clone Project
git clone https://github.com/Tob1as/rpi-sensors.git
# change in folder
cd rpi-sensors/
Use Docker (recommended) or manual installation.
Requirements:
- installed Docker
- installed Docker-Compose
- Help? Use my install Script for that.
- Note: This was developed and tested on a Raspberry Pi 3. On 4 it run when you set
PRIVILEGED_MODE_ENABLE=true
in.env
-File (see below).
Steps:
- copy env-File:
cp example.env .env
- change settings in
.env
-File, example Database Password or GPIO Pin. Then optional check config:docker-compose config
- Run:
or:
docker-compose up -d
docker-compose up -d mariadb dht22 web
- [optional] Logs:
docker-compose logs -f
- [optional] Stop:
docker-compose down -v
- Install requirements:
sudo apt-get update sudo apt-get install -y build-essential python3-dev libgpiod2 libmariadb-dev sudo pip3 install adafruit-blinka==8.43.0 sudo pip3 install adafruit-circuitpython-dht==4.0.5 sudo pip3 install mariadb==1.1.10 sudo pip3 install paho-mqtt==2.1.0
- Setup local or external MariaDB/MySQL.
- Export Variable in
example.env
-File or change default value indht_sensor.py
. - Run:
python3 ./dht_sensor.py
- Optional: Copy html-Folder into Webserver with installed PHP-Modul and change database settings in php file.
If your container (example: web) fails to start with Images that based on Alpine 3.13 on ARM devices like Raspberry with Raspbian Buster (32 bit) then see here or here or here for a possible solution.