muwerk mupplet Sensor Library
muwerk applets; mupplets: functional units that support specific hardware or reusable applications for sensors
Loading...
Searching...
No Matches
Public Member Functions | List of all members
ustd::TempHumDHT Class Reference

mupplet-sensor temperature and humidity with DHT11/22 More...

#include <mup_temphum_dht.h>

Public Member Functions

 TempHumDHT (String name, uint8_t port, uint8_t interruptIndex, DHTType dhtType=DHTType::DHT22, FilterMode filterMode=FilterMode::MEDIUM)
 
double getTemperature ()
 
double getHumidity ()
 

Detailed Description

mupplet-sensor temperature and humidity with DHT11/22

The temphum_dht mupplet measures temperature and humidity using a DHT11 or DHT22 sensor

Messages sent by temphum_dht mupplet:

topic message body comment
<mupplet-name>/sensor/temperature temperature in degree celsius Float value encoded as string
<mupplet-name>/sensor/humidity humidity in percent Float value encoded as string
<mupplet-name>/sensor/mode FAST, MEDIUM, or LONGTERM Integration time for sensor values

Messages received by temphum_dht mupplet:

topic message body comment
<mupplet-name>/sensor/temperature/get - Causes current value to be sent.
<mupplet-name>/sensor/humidity/get - Causes current value to be sent.
<mupplet-name>/sensor/mode/get - Returns filterMode: FAST, MEDIUM, or LONGTERM
<mupplet-name>/sensor/mode/set FAST, MEDIUM, or LONGTERM Set integration time for illuminance values

Sample code

For a complete examples see the muwerk/examples project.

#define __ESP__ 1
#include "scheduler.h"
#include "mup_temphum_dht.h"
ustd::Scheduler sched;
ustd::TempHumDHT dht("myDHT",D4);
void task0(String topic, String msg, String originator) {
if (topic == "myDHT/sensor/temperature") {
Serial.print("Temperature: ");
Serial.prinln(msg); // String float
}
}
void setup() {
dht.begin(&sched);
String name="myDHT";
auto fnall = [=](String topic, String msg, String originator) {
this->subsMsg(topic, msg, originator);
};
pSched->subscribe(tID, name + "/sensor/#", fnall);
}
mupplet-sensor temperature and humidity with DHT11/22
Definition: mup_temphum_dht.h:269

DHT protocol state diagram

..........MCU awakens DHT...............||.........DHT preamble..........|......data bit 1...........|......data bit 2...........| -> 40 data bits.
...........MCU writes...................||..............MCU reads, DHT writes.......................................................
- - - -+ +--------||- - -+ +--- 80us ---+ +- 27us or 70 us -+ +- 27us or 70 us -+
| | | | | | 0bit 1bit | | 0bit 1bit |
| | | | | | | | |
| | | | | | | | |
| | | | | | | | |
+--------// 22ms // ---+ +--- 80us ---+ +--50 us -+ +--50 us -+ + . . . 38 more bits
(1) (2) | (3.1) (3.2) (4) (5)

Constructor & Destructor Documentation

◆ TempHumDHT()

ustd::TempHumDHT::TempHumDHT ( String  name,
uint8_t  port,
uint8_t  interruptIndex,
DHTType  dhtType = DHTType::DHT22,
FilterMode  filterMode = FilterMode::MEDIUM 
)
inline

Instantiate an DHT sensor mupplet

Parameters
nameName used for pub/sub messages
portGPIO port with A/D converter capabilities.
interruptIndexA unique index [0..9] for the interrupt used. If multiple mupplets use interrupts, this index must be unique for each mupplet.
dhtTypeDHT11, DHT22
filterModeFAST, MEDIUM or LONGTERM filtering of sensor values

Member Function Documentation

◆ getHumidity()

double ustd::TempHumDHT::getHumidity ( )
inline

Get current humidity

Returns
Humidity (in percent)

◆ getTemperature()

double ustd::TempHumDHT::getTemperature ( )
inline

Get current temperature

Returns
Temperature (in degrees celsius)

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