RumPi 1.0
A self-assembling C++ sensor & actuator library for the Raspberry Pi 5
RumPi::DHT11 Class Reference

The DHT11 temperature and humidity sensor. More...

#include <DHT11.h>

Inheritance diagram for RumPi::DHT11:
[legend]
Collaboration diagram for RumPi::DHT11:
[legend]

Public Member Functions

 DHT11 (const bool isUsingPi5OrAbove, const unsigned int dhtPinNumber, const unsigned int maxTimings=85U)
 Builds a DHT11 on the given pin. More...
 
virtual ~DHT11 ()
 Destroys the sensor, turning it off first. More...
 
virtual void TurnOn () override
 Turns the sensor on. More...
 
virtual void TurnOff () override
 Turns the sensor off. More...
 
virtual void ProcessRawValues () override
 Reads the sensor (rate-limited to ~once every 2 seconds) and, on a good read, feeds the temperature and humidity into their rolling averages. More...
 
virtual std::string ToString () const override
 Serializes the sensor's current and averaged temperature (Celsius and Fahrenheit) and humidity to a string. More...
 
unsigned int GetDHTPinNumber () const
 Gets the GPIO pin the sensor is wired to. More...
 
unsigned int GetMaxTimings () const
 Gets the maximum number of signal transitions sampled per read (older bit-banged path). More...
 
float GetAverageHumidity () const
 Gets the rolling-average humidity. More...
 
float GetCurrentHumidity () const
 Gets the most recent humidity reading (not averaged). More...
 
float GetAverageTemperatureInCelsius () const
 Gets the rolling-average temperature in Celsius. More...
 
float GetCurrentTemperatureInCelsius () const
 Gets the most recent temperature reading in Celsius (not averaged). More...
 
float GetAverageTemperatureInFahrenheit () const
 Gets the rolling-average temperature converted to Fahrenheit. More...
 
float GetCurrentTemperatureInFahrenheit () const
 Gets the most recent temperature reading converted to Fahrenheit (not averaged). More...
 
- Public Member Functions inherited from RumPi::BaseComponent
 BaseComponent ()
 Builds a base component with an unknown type and an empty name. More...
 
virtual ~BaseComponent ()
 Virtual destructor so deleting a component through a BaseComponent* also cleans up the concrete subclass. More...
 
virtual void TurnOn ()=0
 Turns the component on (e.g. More...
 
virtual void TurnOff ()=0
 Turns the component off. More...
 
virtual std::string ToString () const =0
 Serializes the component's current readings to a string (usually JSON). More...
 
virtual void ProcessRawValues ()=0
 Reads and processes the component's latest raw values (called once per poll). More...
 
virtual EComponentType GetComponentType () const
 Gets the component's type. More...
 
const std::string & GetName () const
 Gets the component's unique per-instance name. More...
 
void SetName (const std::string &name)
 Sets the component's unique per-instance name. More...
 

Private Attributes

bool myIsUsingPi5OrAbove
 Whether to use the Pi 5+ kernel sysfs read path (true) or the older bit-banged GPIO read (false). More...
 
unsigned int myDHTPinNumber
 The GPIO pin the sensor is wired to (older bit-banged path). More...
 
unsigned int myMaxTimings
 Maximum signal transitions to sample per read (older bit-banged path). More...
 
float myCurrentHumidity
 The most recent humidity reading (percent), or NaN if none yet. More...
 
float myCurrentTemperatureInCelsius
 The most recent temperature reading (Celsius), or NaN if none yet. More...
 
RollingAverage myAverageHumidity
 Rolling average of humidity readings. More...
 
RollingAverage myAverageTemperatureInCelsius
 Rolling average of temperature readings (Celsius). More...
 
std::chrono::steady_clock::time_point myLastReadTime
 When the last successful read happened (the sensor needs ~2s between reads). More...
 

Additional Inherited Members

- Static Public Member Functions inherited from RumPi::BaseComponent
static std::string ComponentTypeToString (const EComponentType theComponentTypeToConvert)
 Maps an EComponentType to its string name. More...
 
static EComponentType StringToComponentType (const std::string &theComponentTypeName)
 Maps a type name back to its EComponentType (the inverse of ComponentTypeToString), so the client can turn the type carried on the wire back into a value it can look an icon up with. More...
 
- Protected Attributes inherited from RumPi::BaseComponent
EComponentType myComponentType
 The kind of component this is (set by each concrete subclass). More...
 
std::string myName
 A unique per-instance name, assigned when the component is added to the manager. More...
 

Detailed Description

The DHT11 temperature and humidity sensor.

Its readings tend to fluctuate, so they are averaged over time (via RollingAverage) for a stable value. Supports both the newer Pi 5+ kernel IIO read path and the older bit-banged GPIO read.

Author
Eddie O'Hagan
Date
8/13/2026

Constructor & Destructor Documentation

◆ DHT11()

RumPi::DHT11::DHT11 ( const bool  isUsingPi5OrAbove,
const unsigned int  dhtPinNumber,
const unsigned int  maxTimings = 85U 
)

Builds a DHT11 on the given pin.

Chooses the read path from isUsingPi5OrAbove, and initializes the last-read time to a few seconds ago so the first read is allowed immediately.

Author
Eddie O'Hagan
Date
8/13/2026
DHT11 sensor(true, 13);
DHT11(const bool isUsingPi5OrAbove, const unsigned int dhtPinNumber, const unsigned int maxTimings=85U)
Builds a DHT11 on the given pin.
Definition: DHT11.cpp:24
Parameters
[in]isUsingPi5OrAbovetrue to use the Pi 5+ kernel read path; false for the older bit-banged read.
[in]dhtPinNumberThe GPIO pin the sensor is wired to (older path).
[in]maxTimingsMaximum signal transitions to sample per read (older path).

◆ ~DHT11()

RumPi::DHT11::~DHT11 ( )
virtual

Destroys the sensor, turning it off first.

Author
Eddie O'Hagan
Date
8/13/2026
DHT11* sensor = new DHT11(true, 13);
delete sensor;

Member Function Documentation

◆ GetAverageHumidity()

float RumPi::DHT11::GetAverageHumidity ( ) const

Gets the rolling-average humidity.

Author
Eddie O'Hagan
Date
8/13/2026
float humidity = sensor.GetAverageHumidity();
Returns
The averaged humidity in percent, or NaN if no reading has been taken yet.

◆ GetAverageTemperatureInCelsius()

float RumPi::DHT11::GetAverageTemperatureInCelsius ( ) const

Gets the rolling-average temperature in Celsius.

Author
Eddie O'Hagan
Date
8/13/2026
float tempC = sensor.GetAverageTemperatureInCelsius();
Returns
The averaged temperature in Celsius, or NaN if no reading has been taken yet.

◆ GetAverageTemperatureInFahrenheit()

float RumPi::DHT11::GetAverageTemperatureInFahrenheit ( ) const

Gets the rolling-average temperature converted to Fahrenheit.

Author
Eddie O'Hagan
Date
8/13/2026
float tempF = sensor.GetAverageTemperatureInFahrenheit();
Returns
The averaged temperature in Fahrenheit, or NaN if no reading has been taken yet.

◆ GetCurrentHumidity()

float RumPi::DHT11::GetCurrentHumidity ( ) const

Gets the most recent humidity reading (not averaged).

Author
Eddie O'Hagan
Date
8/13/2026
float humidity = sensor.GetCurrentHumidity();
Returns
The latest humidity reading in percent, or NaN if none yet.

◆ GetCurrentTemperatureInCelsius()

float RumPi::DHT11::GetCurrentTemperatureInCelsius ( ) const

Gets the most recent temperature reading in Celsius (not averaged).

Author
Eddie O'Hagan
Date
8/13/2026
float tempC = sensor.GetCurrentTemperatureInCelsius();
Returns
The latest temperature in Celsius, or NaN if none yet.

◆ GetCurrentTemperatureInFahrenheit()

float RumPi::DHT11::GetCurrentTemperatureInFahrenheit ( ) const

Gets the most recent temperature reading converted to Fahrenheit (not averaged).

Author
Eddie O'Hagan
Date
8/13/2026
float tempF = sensor.GetCurrentTemperatureInFahrenheit();
Returns
The latest temperature in Fahrenheit, or NaN if none yet.

◆ GetDHTPinNumber()

unsigned int RumPi::DHT11::GetDHTPinNumber ( ) const

Gets the GPIO pin the sensor is wired to.

Author
Eddie O'Hagan
Date
8/13/2026
unsigned int pin = sensor.GetDHTPinNumber();
Returns
The sensor's GPIO pin number.

◆ GetMaxTimings()

unsigned int RumPi::DHT11::GetMaxTimings ( ) const

Gets the maximum number of signal transitions sampled per read (older bit-banged path).

Author
Eddie O'Hagan
Date
8/13/2026
unsigned int maxTimings = sensor.GetMaxTimings();
Returns
The configured maximum timings.

◆ ProcessRawValues()

void RumPi::DHT11::ProcessRawValues ( )
overridevirtual

Reads the sensor (rate-limited to ~once every 2 seconds) and, on a good read, feeds the temperature and humidity into their rolling averages.

Uses the Pi 5+ kernel sysfs path or the older bit-banged GPIO read depending on how the sensor was constructed; a failed or flaky read keeps the previous values.

Author
Eddie O'Hagan
Date
8/13/2026
sensor.ProcessRawValues(); //call each poll; internally rate-limited.

Implements RumPi::BaseComponent.

◆ ToString()

std::string RumPi::DHT11::ToString ( ) const
overridevirtual

Serializes the sensor's current and averaged temperature (Celsius and Fahrenheit) and humidity to a string.

Author
Eddie O'Hagan
Date
8/13/2026
std::string data = sensor.ToString();
Returns
A multi-line string of the sensor's readings.

Implements RumPi::BaseComponent.

◆ TurnOff()

void RumPi::DHT11::TurnOff ( )
overridevirtual

Turns the sensor off.

The DHT11 needs no active teardown here, so this is a no-op.

Author
Eddie O'Hagan
Date
8/13/2026
sensor.TurnOff();

Implements RumPi::BaseComponent.

◆ TurnOn()

void RumPi::DHT11::TurnOn ( )
overridevirtual

Turns the sensor on.

The DHT11 needs no active setup here, so this is a no-op.

Author
Eddie O'Hagan
Date
8/13/2026
sensor.TurnOn();

Implements RumPi::BaseComponent.

Member Data Documentation

◆ myAverageHumidity

RollingAverage RumPi::DHT11::myAverageHumidity
private

Rolling average of humidity readings.

◆ myAverageTemperatureInCelsius

RollingAverage RumPi::DHT11::myAverageTemperatureInCelsius
private

Rolling average of temperature readings (Celsius).

◆ myCurrentHumidity

float RumPi::DHT11::myCurrentHumidity
private

The most recent humidity reading (percent), or NaN if none yet.

◆ myCurrentTemperatureInCelsius

float RumPi::DHT11::myCurrentTemperatureInCelsius
private

The most recent temperature reading (Celsius), or NaN if none yet.

◆ myDHTPinNumber

unsigned int RumPi::DHT11::myDHTPinNumber
private

The GPIO pin the sensor is wired to (older bit-banged path).

◆ myIsUsingPi5OrAbove

bool RumPi::DHT11::myIsUsingPi5OrAbove
private

Whether to use the Pi 5+ kernel sysfs read path (true) or the older bit-banged GPIO read (false).

◆ myLastReadTime

std::chrono::steady_clock::time_point RumPi::DHT11::myLastReadTime
private

When the last successful read happened (the sensor needs ~2s between reads).

◆ myMaxTimings

unsigned int RumPi::DHT11::myMaxTimings
private

Maximum signal transitions to sample per read (older bit-banged path).


The documentation for this class was generated from the following files: