8 static const char *
const TAG =
"shtcx";
10 static const uint16_t SHTCX_COMMAND_SLEEP = 0xB098;
11 static const uint16_t SHTCX_COMMAND_WAKEUP = 0x3517;
12 static const uint16_t SHTCX_COMMAND_READ_ID_REGISTER = 0xEFC8;
13 static const uint16_t SHTCX_COMMAND_SOFT_RESET = 0x805D;
14 static const uint16_t SHTCX_COMMAND_POLLING_H = 0x7866;
23 return "[Unknown model]";
28 ESP_LOGCONFIG(TAG,
"Setting up SHTCx...");
33 ESP_LOGE(TAG,
"Error requesting Device ID");
38 uint16_t device_id_register;
39 if (!this->
read_data(&device_id_register, 1)) {
40 ESP_LOGE(TAG,
"Error reading Device ID");
47 if ((device_id_register & 0x3F) == 0x07) {
48 if (device_id_register & 0x800) {
56 ESP_LOGCONFIG(TAG,
" Device identified: %s (%04x)",
to_string(this->
type_), device_id_register);
59 ESP_LOGCONFIG(TAG,
"SHTCx:");
63 ESP_LOGE(TAG,
"Communication with SHTCx failed!");
65 LOG_UPDATE_INTERVAL(
this);
73 ESP_LOGW(TAG,
"Retrying to reconnect the sensor.");
80 ESP_LOGE(TAG,
"sensor polling failed");
94 ESP_LOGE(TAG,
"sensor read failed");
97 temperature = 175.0f * float(raw_data[0]) / 65536.0f - 45.0f;
98 humidity = 100.0f * float(raw_data[1]) / 65536.0f;
100 ESP_LOGD(TAG,
"Got temperature=%.2f°C humidity=%.2f%%", temperature, humidity);
const float DATA
For components that import data from directly connected sensors like DHT.
const char * to_string(SHTCXType type)
void status_set_warning(const char *message="unspecified")
bool status_has_warning() const
bool write_command(T i2c_register)
Write a command to the i2c device.
void dump_config() override
void set_timeout(const std::string &name, uint32_t timeout, std::function< void()> &&f)
Set a timeout function with a unique name.
bool read_data(uint16_t *data, uint8_t len)
Read data words from i2c device.
sensor::Sensor * humidity_sensor_
void status_clear_warning()
void publish_state(float state)
Publish a new state to the front-end.
virtual void mark_failed()
Mark this component as failed.
Implementation of SPI Controller mode.
void IRAM_ATTR HOT delayMicroseconds(uint32_t us)
sensor::Sensor * temperature_sensor_
float get_setup_priority() const override