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;
void task0(String topic, String msg, String originator) {
if (topic == "myDHT/sensor/temperature") {
Serial.print("Temperature: ");
Serial.prinln(msg);
}
}
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 |
| | | | | | | | |
| | | | | | | | |
| | | | | | | | |
+--------
(1) (2) | (3.1) (3.2) (4) (5)