Skip to content

mathew-hall/esp8266-dht

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

58 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ESP8266-based DHT11 (and 22) logger

This application builds on Martin's DHT22 webserver implementation, which uses sprite_tm's ESP8266 httpd.

This version adds a check to make sure a DHT sensor is connected, and prevents the sensor being polled past the manufacturer's maximum frequency. It also logs sensor readings to a remote machine over the network as JSON, sent over UDP.

In addition to a DHT sensor, a DS18B20 1wire temperature sensor can be attached to port 0. If there's one attached, readings will be sent to the logging server and shown in the dht22.tpl page on the webserver.

If enabled (default is off), the code will try to sleep the ESP chip rather than leave it running. This requires a physical connection between the RST and GPIO16 pin, otherwise the chip won't wake up after going to sleep. The cycle time in "sleep mode" is about one minute. See Issue #3 for the needed fix to allow the board to wake back up.

Configuration

There are a few parameters that can be changed:

  • user/user_main.c: sensor type (DHT11 or DHT22) and poll rate
  • tempd.c: hostname and UDP port to send readings, poll rate for readings, fallback IP (needs to be set in dnsLookupCb), and sleep mode setting (default off)

Building

Make sure the IoT SDK and toolchain are set up according to the instructions on the ESP8266 wiki. The makefile in this project relies on some environment variables that need to be set. It should be enough to add these to your .profile:

PATH="/opt/Espressif/crosstool-NG/builds/xtensa-lx106-elf/bin/:$PATH"
export SDK_BASE="/opt/Espressif/ESP8266_SDK"
export XTENSA_TOOLS_ROOT="/opt/Espressif/crosstool-NG/builds/xtensa-lx106-elf/bin/"
export ESPTOOL="/opt/Espressif/esptool-py/esptool.py"

From the root of this repository, run make. This will build the two firmware images. To update the webserver's HTML files, run make webpages.espfs.

Hardware

The whole circuit runs on 3.3V power, which can be obtained using a cheap AMS1117 3.3V module or regulator circuit.

Pin Connection
VCC and CH_PD +3.3V
GPIO0 DS18B20 DQ pin, pulled to 3.3V through a 4.7k resistor
GPIO2 DHT11 pin 2, pulled to 3.3V through a 10k resistor
GND ground
TX UART adapter RX
RX UART adapter TX
RST N/C [or solder to GPIO16 on the module for sleep mode]

The sensors both need their VCC and GND pins connecting to power and ground respectively.

Sleep mode

The sleep mode requires the RST pin to be tied to GPIO16 to allow the chip to wake itself back up. If this change isn't made (and sleep mode is turned on in tempd.c) then the board will post a single update and then not do anything until manually reset.

You'll need to solder a wire from RST to GPIO16. See Issue #3 for the needed bodge. The pitch on the chip is very small, so use a very thin wire. I used an individual strand from an IDE cable.

This might not apply for newer ESP modules.

Licenses

This code is entirely based on Sprite_tm's httpd implementation for the ESP8266, licensed under the Beer-ware license. See the license headers in the user directory for the full text of the license.

The webserver uses Scott Vokes's heatshrink library. See the LICENSE file in lib/heatshrink for the full text of the license.

The DHT code is based on Martin's DHT22 cgi script. The revised DHT driver itself is based on the implementation from Adafruit Industries. See the comment in dht.c for the full text of the license. Code for the CRC calculation is taken from Maxim AN162.

The ds18b20 driver includes code based on Grant Forest's Energia code and licensed under the GPL. See the file for the full license text.

The temperature logger is licensed under a modified Beer-wrare license. See the header for tempd.c for details.

About

Temperature logging and web UI for the ESP8266 WiFi module

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published