14 static const char *
const TAG =
"am2320";
25 float temperature = (((data[4] & 0x7F) << 8) + data[5]) / 10.0f;
26 temperature = (data[4] & 0x80) ? -temperature : temperature;
27 float humidity = ((data[2] << 8) + data[3]) / 10.0f;
29 ESP_LOGD(TAG,
"Got temperature=%.1f°C humidity=%.1f%%", temperature, humidity);
37 ESP_LOGCONFIG(TAG,
"Setting up AM2320...");
47 ESP_LOGD(TAG,
"AM2320:");
50 ESP_LOGE(TAG,
"Communication with AM2320 failed!");
59 ESP_LOGW(TAG,
"Writing bytes for AM2320 failed!");
74 ESP_LOGW(TAG,
"Updating AM2320 failed!");
80 checksum = data[7] << 8;
83 if (
crc16(data, 6) != checksum) {
84 ESP_LOGW(TAG,
"AM2320 Checksum invalid!");
const float DATA
For components that import data from directly connected sensors like DHT.
bool read_bytes_(uint8_t a_register, uint8_t *data, uint8_t len, uint32_t conversion=0)
sensor::Sensor * temperature_sensor_
void status_set_warning(const char *message="unspecified")
sensor::Sensor * humidity_sensor_
ErrorCode read(uint8_t *data, size_t len)
reads an array of bytes from the device using an I2CBus
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.
No error found during execution of method.
void status_clear_warning()
void publish_state(float state)
Publish a new state to the front-end.
void dump_config() override
float get_setup_priority() const override
virtual void mark_failed()
Mark this component as failed.
Implementation of SPI Controller mode.
bool read_data_(uint8_t *data)
void IRAM_ATTR HOT delay(uint32_t ms)
bool write_bytes(uint8_t a_register, const uint8_t *data, uint8_t len, bool stop=true)