Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Tob1as/rpi-sensors

Open more actions menu

Repository files navigation

Raspberry Pi Sensors (rpi-sensors)

Description

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.

Requirements

  • Raspberry Pi
  • Raspberry Pi OS (previously called Raspbian), Version: 10 buster / 11 bullseye
  • Sensor: DHT22 (AM2302) (Buy: int./de)
  • optional: Docker & docker-compose

Installation / Usage

Note:

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.

First Step:

# Clone Project 
git clone https://github.com/Tob1as/rpi-sensors.git
# change in folder
cd rpi-sensors/

Secend Step:

Use Docker (recommended) or manual installation.

Docker

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:

  1. copy env-File:
    cp example.env .env
  2. change settings in .env-File, example Database Password or GPIO Pin. Then optional check config:
    docker-compose config
  3. Run:
    docker-compose up -d
    or:
    docker-compose up -d mariadb dht22 web
  4. [optional] Logs:
    docker-compose logs -f
  5. [optional] Stop:
    docker-compose down -v

manual installation

  1. 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
  2. Setup local or external MariaDB/MySQL.
  3. Export Variable in example.env-File or change default value in dht_sensor.py.
  4. Run:
    python3 ./dht_sensor.py
  5. Optional: Copy html-Folder into Webserver with installed PHP-Modul and change database settings in php file.

Troubleshooting

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.

This on

  • DockerHub for Container/Docker Image
  • GitHub for Sourcecode and configuration
Morty Proxy This is a proxified and sanitized view of the page, visit original site.