This repository contains a reference implementation of a DHT22 temperature sensor that reports the sensor temperature and humidity to STDOUT and an MQTT broker.
- Raspberry Pi (tested on Pi 0 W, should also work on Pi 2/3 and I suspect any other Pi with a network connection available).
- DHT22 temperature sensor
- Docker installed on Raspberry Pi with Docker-compose (docker-compose convenient, but not required)
From https://pinout.xyz.
This is how I have my DHT22 wired. A resistor is probably required or at least strongly recommended, but mine works fine without one. If one was required, my research suggested it should be 5k-10k resistor between the data and ground pins.
- 3.3v (bottom left) to left hand pin on DHT22 (with intake grill facing up)
- GPIO4 (4th from left) to second-from-left pin on DHT22
- Ground (bottom right) to right hand pin on DHT22
With the DHT22 set up as above, I run this using docker-compose up -d
on my raspberry pi. Here are
some notes that may help with your specific setup:
- I have my own environment variables in
docker-compose.yml
. You will need to provide your own. - I have not added support for an MQTT username/password as my broker just operates within my local network.
- GPIO pin 4 is hardcoded - just change it in
fetch.py
to whatever you'd prefer. - The
privileged: true
flag indocker-compose.yml
is needed so that the Adafruit DHT22 library can see and communicate with GPIO. There are other ways of accessing GPIO with Docker, but privileged mode is the easiest and the one that consistently works.
See LICENSE. Please note that Adafruit_DHT
is bootstrapped by the Dockerfile
in this project and
is MIT licensed as of release. See
https://github.com/adafruit/Adafruit_Python_DHT/blob/master/LICENSE for more information.