7static const char *
const TAG =
"sts3x";
9static const uint16_t STS3X_COMMAND_READ_SERIAL_NUMBER = 0x3780;
10static const uint16_t STS3X_COMMAND_READ_STATUS = 0xF32D;
11static const uint16_t STS3X_COMMAND_SOFT_RESET = 0x30A2;
12static const uint16_t STS3X_COMMAND_POLLING_H = 0x2400;
15static const uint16_t STS3X_COMMAND_CLEAR_STATUS = 0x3041;
16static const uint16_t STS3X_COMMAND_HEATER_ENABLE = 0x306D;
17static const uint16_t STS3X_COMMAND_HEATER_DISABLE = 0x3066;
18static const uint16_t STS3X_COMMAND_FETCH_DATA = 0xE000;
21 ESP_LOGCONFIG(TAG,
"Setting up STS3x...");
27 uint16_t raw_serial_number[2];
28 if (!this->
read_data(raw_serial_number, 1)) {
32 uint32_t
serial_number = (uint32_t(raw_serial_number[0]) << 16);
36 ESP_LOGCONFIG(TAG,
"STS3x:");
39 ESP_LOGE(TAG,
"Communication with ST3x failed!");
41 LOG_UPDATE_INTERVAL(
this);
43 LOG_SENSOR(
" ",
"STS3x",
this);
48 ESP_LOGD(TAG,
"Retrying to reconnect the sensor.");
63 float temperature = 175.0f * float(raw_data[0]) / 65535.0f - 45.0f;
64 ESP_LOGD(TAG,
"Got temperature=%.2f°C",
temperature);
virtual void mark_failed()
Mark this component as failed.
bool status_has_warning() const
void status_set_warning(const char *message="unspecified")
void status_clear_warning()
void set_timeout(const std::string &name, uint32_t timeout, std::function< void()> &&f)
Set a timeout function with a unique name.
bool write_command(T i2c_register)
Write a command to the i2c device.
bool read_data(uint16_t *data, uint8_t len)
Read data words from i2c device.
void publish_state(float state)
Publish a new state to the front-end.
float get_setup_priority() const override
void dump_config() override
const float DATA
For components that import data from directly connected sensors like DHT.
Providing packet encoding functions for exchanging data with a remote host.