Skip to content

Latest commit

 

History

History
104 lines (78 loc) · 4.53 KB

API.md

File metadata and controls

104 lines (78 loc) · 4.53 KB

Warning

dht API is a subject of change

Nothing below can not be assumed as valid

Functions

void setup(uint8_t pin, DHT_MODEL_t model=AUTO_DETECT);

  • Call to initialize the interface, define the GPIO pin to which the sensor is connected and define the sensor type. Valid sensor types are:
    • AUTO_DETECT Try to detect which sensor is connected
    • DHT11
    • DHT22
    • AM2302 Packaged DHT22
    • RHT03 Equivalent to DHT22

void resetTimer();

  • Reset last time the sensor was read

float getTemperature();

  • Get the temperature in degree Centigrade from the sensor
    Either one of getTemperature() or getHumidity() or getTempAndHumidity() initiates reading a value from the sensor if the last reading was older than the minimal refresh time of the sensor.
    See example DHT_ESP32.ino or DHT_Test.ino

float getHumidity();

  • Get the humidity from the sensor
    Either one of getTemperature() or getHumidity() or getTempAndHumidity() initiates reading a value from the sensor if the last reading was older than the minimal refresh time of the sensor.
    See example DHT_ESP32.ino or DHT_Test.ino

TempAndHumidity getTempAndHumidity();

  • Get the temperature and humidity from the sensor
    Either one of getTemperature() or getHumidity() or getTempAndHumidity() initiates reading a value from the sensor if the last reading was older than the minimal refresh time of the sensor.
    Return value is a struct of type TempAndHumidity with temperature and humidity as float values. See example DHT_Multi.ino

DHT_ERROR_t getStatus();

  • Get last error if reading from the sensor failed. Possible values are:
    • ERROR_NONE no error occured
    • ERROR_TIMEOUT timeout reading from the sensor
    • ERROR_CHECKSUM checksum of received values doesn't match

const char* getStatusString();

  • Get last error as a char *

DHT_MODEL_t getModel()

  • Get detected (or defined) sensor type

int getMinimumSamplingPeriod();

  • Get minimmum possible sampling period. For DHT11 this is 1000ms, for other sensors it is 2000ms

int8_t getNumberOfDecimalsTemperature();

  • Get number of decimals in the temperature value. For DHT11 this is 0, for other sensors it is 1

int8_t getLowerBoundTemperature();

  • Get lower temperature range of the sensor. For DHT11 this is 0 degree Centigrade, for other sensors this is -40 degree Centrigrade

int8_t getUpperBoundTemperature();

  • Get upper temperature range of the sensor. For DHT11 this is 50 degree Centigrade, for other sensors this is 125 degree Centrigrade

int8_t getNumberOfDecimalsHumidity();

  • Get number of decimals in the humidity value. This is always 0.

int8_t getLowerBoundHumidity();

  • Get lower humidity range of the sensor. For DHT11 this is 20 percent, for other sensors this is 0 percent

int8_t getUpperBoundHumidity();

  • Get upper temperature range of the sensor. For DHT11 this is 90 percent, for other sensors this is 100 percent

static float toFahrenheit(float fromCelcius);

  • Convert Centrigrade value to Fahrenheit value

static float toCelsius(float fromFahrenheit) { return (fromFahrenheit - 32.0) / 1.8; };

  • Convert Fahrenheit value to Centigrade value

float computeHeatIndex(float temperature, float percentHumidity, bool isFahrenheit=false);

  • Compute the heat index. Default temperature is in Centrigrade.

float computeDewPoint(float temperature, float percentHumidity, bool isFahrenheit=false);

  • Compute the dew point. Default temperature is in Centrigrade.

float getComfortRatio(ComfortState& destComfStatus, float temperature, float percentHumidity, bool isFahrenheit=false);

  • Compute the comfort ratio. Default temperature is in Centrigrade. Return values:
    0 -> OK
    1 -> Too Hot
    2 -> Too cold
    4 -> Too dry
    8 -> Too humid
    9 -> Hot and humid
    5 -> Hot and dry
    10 -> Cold and humid
    6 -> Cold and dry

byte computePerception(float temperature, float percentHumidity, bool isFahrenheit=false);

  • Compute the human perception. Default temperature is in Centrigrade. Return values:
    0 -> Dry
    1 -> Very comfortable
    2 -> Comfortable
    3 -> Ok
    4 -> Uncomfortable
    5 -> Quite uncomfortable
    6 -> Very uncomfortable
    7 -> Severe uncomfortable