A lightweight C implementation for reading DHT11 temperature and humidity sensors on Raspberry Pi.
makesudo make installAdd the WildlifeSystems APT repository to your system
sudo apt update
sudo apt install sensor-dht11# Read all sensors (temperature and humidity)
sensor-dht11
# Read all sensors explicitly
sensor-dht11 all
# Read only temperature
sensor-dht11 temperature
# Read only humidity
sensor-dht11 humidity
# Read only internal sensors
sensor-dht11 internal
# Read only external sensors
sensor-dht11 external
# List available sensor types
sensor-dht11 list
# Identify (exits with code 60)
sensor-dht11 identify
# Show version
sensor-dht11 version
# Output mock data for testing
sensor-dht11 mockConfiguration is read from /etc/ws/sensors/dht11.json. Example:
[
{
"pin": 4,
"internal": false
}
]pin: GPIO pin number (2-27)internal: Boolean indicating if sensor is inside the enclosuresensor_id: Optional custom sensor ID (defaults to Pi serial + "_dht11")
The program outputs JSON in the WildlifeSystems sensor format:
[
{"sensor":"dht11_temperature","measures":"temperature","unit":"Celsius","value":23.0,"internal":false,"sensor_id":"1234567890abcdef_dht11_temperature"},
{"sensor":"dht11_humidity","measures":"humidity","unit":"percentage","value":45.0,"internal":false,"sensor_id":"1234567890abcdef_dht11_humidity"}
]This program uses a userspace C implementation to read DHT11 sensors via GPIO using the libgpiod library. All timing-critical bit-banging is handled in userspace with SCHED_FIFO real-time scheduling to minimise preemption-related timing failures.
0: Success20: Invalid argument60: Identify command
Performance comparison between C and previous Python versions
Ed Baker ed@ebaker.me.uk
Part of the WildlifeSystems project. For more information, visit: