10static constexpr size_t EE895_SERIAL_NUMBER_SIZE = 16;
12static const uint16_t CRC16_ONEWIRE_START = 0xFFFF;
13static const uint8_t FUNCTION_CODE_READ = 0x03;
14static const uint16_t SERIAL_NUMBER = 0x0000;
15static const uint16_t TEMPERATURE_ADDRESS = 0x03EA;
16static const uint16_t CO2_ADDRESS = 0x0424;
17static const uint16_t PRESSURE_ADDRESS = 0x04B0;
20 uint16_t crc16_check = 0;
23 this->
read(serial_number, 20);
30#if ESPHOME_LOG_LEVEL >= ESPHOME_LOG_LEVEL_VERBOSE
36void EE895Component::dump_config() {
37 ESP_LOGCONFIG(TAG,
"EE895:");
39 LOG_UPDATE_INTERVAL(
this);
40 LOG_SENSOR(
" ",
"Temperature", this->temperature_sensor_);
41 LOG_SENSOR(
" ",
"CO2", this->co2_sensor_);
42 LOG_SENSOR(
" ",
"Pressure", this->pressure_sensor_);
45void EE895Component::update() {
55 ESP_LOGD(TAG,
"Got temperature=%.1f°C co2=%.0fppm pressure=%.1f%mbar",
temperature, co2,
pressure);
56 PUBLISH_STATE(this->temperature_sensor_,
temperature);
57 PUBLISH_STATE(this->co2_sensor_, co2);
58 PUBLISH_STATE(this->pressure_sensor_,
pressure);
66 address[0] = FUNCTION_CODE_READ;
67 address[1] = (addr >> 8) & 0xFF;
69 address[3] = (reg_cnt >> 8) & 0xFF;
74 this->
write(address, 7);
78 uint16_t crc16_check = 0;
79 uint8_t i2c_response[8];
80 this->
read(i2c_response, 8);
81 crc16_check = (i2c_response[7] << 8) + i2c_response[6];
94 uint16_t crc =
crc16(&addr, 1);
void mark_failed()
Mark this component as failed.
virtual void setup()
Where the component's initialization should happen.
void status_set_warning()
void set_timeout(const char *name, uint32_t timeout, std::function< void()> &&f)
Set a timeout function with a const char* name.
void status_clear_warning()
void write_command_(uint16_t addr, uint16_t reg_cnt)
uint16_t calc_crc16_(const uint8_t buf[], uint8_t len)
ErrorCode write(const uint8_t *data, size_t len) const
writes an array of bytes to a device using an I2CBus
ErrorCode read(uint8_t *data, size_t len) const
reads an array of bytes from the device using an I2CBus
uint8_t address_
store the address of the device on the bus
ESPHOME_LOG_TAG(TAG, "ee895")
uint16_t crc16(const uint8_t *data, uint16_t len, uint16_t crc, uint16_t reverse_poly, bool refin, bool refout)
Calculate a CRC-16 checksum of data with size len.
constexpr size_t format_hex_size(size_t byte_count)
Calculate buffer size needed for format_hex_to: "XXXXXXXX...\0" = bytes * 2 + 1.
constexpr uint32_t encode_uint32(uint8_t byte1, uint8_t byte2, uint8_t byte3, uint8_t byte4)
Encode a 32-bit value given four bytes in most to least significant byte order.
char * format_hex_to(char *buffer, size_t buffer_size, const uint8_t *data, size_t length)
Format byte array as lowercase hex to buffer (base implementation).