DHT11 readout library
Functions
dht11.c File Reference

A library to access the DHT11 temperature and humidity sensor. This device uses its own one wire protocol and the library allows to

Copyright U. Raich Oct. 2017
This program is part of a course on embedded systems held at the University of Cape Coast, Ghana in 2017
It is released under the GNU Public License.
For details please see https://www.gnu.org/licenses/gpl.html
More...

#include <stdio.h>
#include <stdlib.h>
#include <wiringPi.h>
#include "dht11.h"
Include dependency graph for dht11.c:

Functions

void dht11SetDebug (bool onOff)
 switches debug mode on or off More...
 
void dht11PrintError (int err)
 prints an error message in human understandable form More...
 
void dht11Init ()
 connects to the wiringPi library
 
int dht11Measurement ()
 make a measurement and saves the data in an internal array returns DHT11_SUCCESS if successful DHT11_MISSING_INIT if dht11Init has not been called before
 
int dht11GetTemperature ()
 returns the measured temperature value in degrees C More...
 
int dht11GetValidTemperature ()
 returns the measured temperature value in degrees C More...
 
int dht11GetHumidity ()
 returns the measured humidity value in % More...
 
int dht11GetValidHumidity ()
 returns the measured humidity value in % More...
 
time_t dht11GetMeasTimeStamp ()
 returns the time stamp of the last measurement More...
 
time_t dht11GetValidMeasTimeStamp ()
 returns the time stamp of the last valid measurement More...
 
int dht11GetRawData (int *rawData)
 returns the measured data independent of the checksum test More...
 
int dht11GetValidRawData (int *rawData)
 returns the measured data which were checked by the checksum test More...
 
int dht11GetChecksum ()
 returns the checksum as calculated from the data
 
int dht11GetDeviceChecksum ()
 returns the checksum as read from the dht11
 

Detailed Description

A library to access the DHT11 temperature and humidity sensor. This device uses its own one wire protocol and the library allows to

Copyright U. Raich Oct. 2017
This program is part of a course on embedded systems held at the University of Cape Coast, Ghana in 2017
It is released under the GNU Public License.
For details please see https://www.gnu.org/licenses/gpl.html

:

Author
Uli Raich

Function Documentation

int dht11GetHumidity ( void  )

returns the measured humidity value in %

Returns
The last humidity data measured independent of the checksum result System interrupts may disturb reading of the data stream from the DHT11 and corrupt the data. This is checked for by comparing the calculated checksum with the one sent by the DHT11. This call returns the humidity data without the checksum test.
time_t dht11GetMeasTimeStamp ( void  )

returns the time stamp of the last measurement

Returns
The time stamp independent of the checksum test
int dht11GetRawData ( int *  rawData)

returns the measured data independent of the checksum test

Parameters
int*rawData is a pointer to an integer array of a size of at least DHT11_PROTOCOL_SIZE integer values. If a NULL pointer is passed to the routine, it will allocate memory space big enough to hold the data. In this case the caller must free the allocated memory after use
int dht11GetTemperature ( void  )

returns the measured temperature value in degrees C

Returns
The last temperature measured independent of the checksum result System interrupts may disturb reading of the data stream from the DHT11 and corrupt the data. This is checked for by comparing the calculated checksum with the one sent by the DHT11. This call returns the temperature data without the checksum test.
int dht11GetValidHumidity ( void  )

returns the measured humidity value in %

Returns
The last temperature measured with correct checksum this returns valid temperature data
time_t dht11GetValidMeasTimeStamp ( void  )

returns the time stamp of the last valid measurement

Returns
The time stamp of the last measurement having passed the checksum test. You can print the time stamp in a humanly readable format with:
timeStamp = dht11GetMeasTimeStamp();
printf("%s\n",ctime(&timeStamp));
int dht11GetValidRawData ( int *  rawData)

returns the measured data which were checked by the checksum test

Parameters
int*rawData is a pointer to an integer array of a size of at least DHT11_PROTOCOL_SIZE integer values. If a NULL pointer is passed to the routine, it will allocate memory space bit enough to hold the data. In this case the caller must free the allocated memory after use
int dht11GetValidTemperature ( void  )

returns the measured temperature value in degrees C

Returns
The last temperature measured with correct checksum this returns valid temperature data
void dht11PrintError ( int  err)

prints an error message in human understandable form

Parameters
anerror code returned by the library
void dht11SetDebug ( bool  onOff)

switches debug mode on or off

Parameters
onOfftrue: switches debug mode on
false: switches debug mode off