8static const char *
const TAG =
"tmp102";
10static const uint8_t TMP102_ADDRESS = 0x48;
11static const uint8_t TMP102_REGISTER_TEMPERATURE = 0x00;
12static const uint8_t TMP102_REGISTER_CONFIGURATION = 0x01;
13static const uint8_t TMP102_REGISTER_LOW_LIMIT = 0x02;
14static const uint8_t TMP102_REGISTER_HIGH_LIMIT = 0x03;
16static const float TMP102_CONVERSION_FACTOR = 0.0625;
21 ESP_LOGCONFIG(TAG,
"TMP102:");
24 ESP_LOGE(TAG,
"Communication with TMP102 failed!");
26 LOG_UPDATE_INTERVAL(
this);
27 LOG_SENSOR(
" ",
"Temperature",
this);
36 int16_t raw_temperature;
37 if (this->
read(
reinterpret_cast<uint8_t *
>(&raw_temperature), 2) !=
i2c::ERROR_OK) {
42 raw_temperature = raw_temperature >> 4;
43 float temperature = raw_temperature * TMP102_CONVERSION_FACTOR;
44 ESP_LOGD(TAG,
"Got Temperature=%.1f°C",
temperature);
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.
ErrorCode write(const uint8_t *data, size_t len, bool stop=true)
writes an array of bytes to a device using an I2CBus
ErrorCode read(uint8_t *data, size_t len)
reads an array of bytes from the device using an I2CBus
void publish_state(float state)
Publish a new state to the front-end.
void dump_config() override
void update() override
Update the sensor values (temperature)
float get_setup_priority() const override
void setup() override
Setup (reset) the sensor and check connection.
uint16_t i2ctohs(uint16_t i2cshort)
@ ERROR_OK
No error found during execution of method.
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.