Building A Remote Temperature and Humidity Sensor Web-Service Using A DHT22 Sensor and a Raspberry Pi 3B+

From Nearline Storage
Revision as of 16:05, 21 January 2020 by Dlk (talk | contribs) (Created page with "==Materials Required== *[https://www.google.com/search&q=raspberry+pi+3+b%2B&tbm=shop Raspberry Pi 3B+] (Any Pi will do, as long as it has wifi for communications.) *[https://...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Jump to navigation Jump to search

Materials Required

  • Raspberry Pi 3B+ (Any Pi will do, as long as it has wifi for communications.)
  • Mini SD card, 8GB or larger (For this application there's no advantage to having an SD card that's any larger than the minimum requirement.)
  • DHT22/AM2302 temperature and humidity sensor (I assume that the 3-pin version of this sensor is being used here. There is also a 4-pin version available that may, or may not, require that a resistor be soldered in between two of the pins.)
  • Block of wood for mounting (optional)
  • Small wood screws for mounting (optional)

Instructions

  • Setup the Raspberry Pi
    • These instructions provide guidance on formatting the SD card using a program on Mac or Windows. See this tutorial for instructions on how to do the same thing on a Linux computer.
  • We will ultimately want to run the Pi as a headless system, i.e., without a keyboard or display attached, so set up ssh for remote access to a terminal.
    • Make sure that the Pi has a static IP address on the network, and even perhaps a hostname.
If the Pi is to be accessed remotely, it must have an IP address that is known. Associating that address with a hostname makes things even easier. Typically these would be things that would be configured through DHCP and DNS settings on the local network router. The exact details vary so I won't try to cover them here.
  • With the Pi powered off, connect the DHT22 sensor.
  • Add an entry for the DBUS "driver" for the DHT22 sensor to /boot/config.txt
  • Create a web service on the Raspberry Pi that any computer on your network can query to get the current temperature and humidity.
    • Install a web server and the PHO scripting language.
    • Modify the web server's home page to turn it into the web service.