11 static const char *
const TAG =
"dht12";
19 const uint16_t raw_temperature = uint16_t(data[2]) * 10 + (data[3] & 0x7F);
21 if ((data[3] & 0x80) != 0) {
26 const uint16_t raw_humidity = uint16_t(data[0]) * 10 + data[1];
27 float humidity = raw_humidity / 10.0f;
29 ESP_LOGD(TAG,
"Got temperature=%.2f°C humidity=%.2f%%", temperature, humidity);
37 ESP_LOGCONFIG(TAG,
"Setting up DHT12...");
45 ESP_LOGD(TAG,
"DHT12:");
48 ESP_LOGE(TAG,
"Communication with DHT12 failed!");
56 ESP_LOGW(TAG,
"Updating DHT12 failed!");
60 uint8_t
checksum = data[0] + data[1] + data[2] + data[3];
61 if (data[4] != checksum) {
62 ESP_LOGW(TAG,
"DHT12 Checksum invalid!");
const float DATA
For components that import data from directly connected sensors like DHT.
sensor::Sensor * humidity_sensor_
bool read_data_(uint8_t *data)
void status_set_warning(const char *message="unspecified")
bool read_bytes(uint8_t a_register, uint8_t *data, uint8_t len)
Compat APIs All methods below have been added for compatibility reasons.
sensor::Sensor * temperature_sensor_
void status_clear_warning()
float get_setup_priority() const override
void publish_state(float state)
Publish a new state to the front-end.
void dump_config() override
virtual void mark_failed()
Mark this component as failed.
Implementation of SPI Controller mode.