8 static const char *
const TAG =
"ee895";
10 static const uint16_t CRC16_ONEWIRE_START = 0xFFFF;
11 static const uint8_t FUNCTION_CODE_READ = 0x03;
12 static const uint16_t SERIAL_NUMBER = 0x0000;
13 static const uint16_t TEMPERATURE_ADDRESS = 0x03EA;
14 static const uint16_t CO2_ADDRESS = 0x0424;
15 static const uint16_t PRESSURE_ADDRESS = 0x04B0;
18 uint16_t crc16_check = 0;
19 ESP_LOGCONFIG(TAG,
"Setting up EE895...");
22 this->
read(serial_number, 20);
24 crc16_check = (serial_number[19] << 8) + serial_number[18];
25 if (crc16_check !=
calc_crc16_(serial_number, 19)) {
30 ESP_LOGV(TAG,
" Serial Number: 0x%s",
format_hex(serial_number + 2, 16).c_str());
34 ESP_LOGCONFIG(TAG,
"EE895:");
36 switch (this->error_code_) {
38 ESP_LOGE(TAG,
"Communication with EE895 failed!");
41 ESP_LOGE(TAG,
"The crc check failed");
47 LOG_UPDATE_INTERVAL(
this);
65 ESP_LOGD(TAG,
"Got temperature=%.1f°C co2=%.0fppm pressure=%.1f%mbar", temperature, co2, pressure);
79 address[0] = FUNCTION_CODE_READ;
80 address[1] = (addr >> 8) & 0xFF;
81 address[2] = addr & 0xFF;
82 address[3] = (reg_cnt >> 8) & 0xFF;
83 address[4] = reg_cnt & 0xFF;
85 address[5] = crc16 & 0xFF;
86 address[6] = (crc16 >> 8) & 0xFF;
87 this->
write(address, 7,
true);
91 uint16_t crc16_check = 0;
92 uint8_t i2c_response[8];
93 this->
read(i2c_response, 8);
94 crc16_check = (i2c_response[7] << 8) + i2c_response[6];
100 uint32_t
x =
encode_uint32(i2c_response[4], i2c_response[5], i2c_response[2], i2c_response[3]);
102 memcpy(&value, &x,
sizeof(value));
107 uint8_t crc_check_buf[22];
108 for (
int i = 0; i <
len; i++) {
109 crc_check_buf[i + 1] = buf[i];
112 return crc16(crc_check_buf, len);
sensor::Sensor * temperature_sensor_
const float DATA
For components that import data from directly connected sensors like DHT.
std::string format_hex(const uint8_t *data, size_t length)
Format the byte array data of length len in lowercased hex.
void status_set_warning(const char *message="unspecified")
ErrorCode read(uint8_t *data, size_t len)
reads an array of bytes from the device using an I2CBus
void set_timeout(const std::string &name, uint32_t timeout, std::function< void()> &&f)
Set a timeout function with a unique name.
float get_setup_priority() const override
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.
sensor::Sensor * co2_sensor_
void dump_config() override
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.
ErrorCode write(const uint8_t *data, size_t len, bool stop=true)
writes an array of bytes to a device using an I2CBus
enum esphome::ee895::EE895Component::ErrorCode NONE
void status_clear_warning()
void publish_state(float state)
Publish a new state to the front-end.
uint16_t calc_crc16_(const uint8_t buf[], uint8_t len)
sensor::Sensor * pressure_sensor_
uint8_t address_
store the address of the device on the bus
virtual void mark_failed()
Mark this component as failed.
Implementation of SPI Controller mode.
void write_command_(uint16_t addr, uint16_t reg_cnt)