8static const uint8_t PM1006_RESPONSE_HEADER[] = {0x16, 0x11, 0x0B};
9static const uint8_t PM1006_REQUEST[] = {0x11, 0x02, 0x0B, 0x01, 0xE1};
16 ESP_LOGCONFIG(TAG,
"PM1006:");
18 LOG_UPDATE_INTERVAL(
this);
22 ESP_LOGV(TAG,
"sending measurement request");
23 this->
write_array(PM1006_REQUEST,
sizeof(PM1006_REQUEST));
30 if (!check.has_value()) {
36 ESP_LOGV(TAG,
"Byte %i of received data frame is invalid.", this->
data_index_);
51 const uint8_t
byte = this->
data_[index];
54 if (index <
sizeof(PM1006_RESPONSE_HEADER)) {
55 return byte == PM1006_RESPONSE_HEADER[index];
64 if (index < (
sizeof(PM1006_RESPONSE_HEADER) + 16))
68 if (index == (
sizeof(PM1006_RESPONSE_HEADER) + 16)) {
71 ESP_LOGW(TAG,
"PM1006 checksum is wrong: %02x, expected zero",
checksum);
83 ESP_LOGD(TAG,
"Got PM2.5 Concentration: %d µg/m³", pm_2_5_concentration);
uint8_t pm1006_checksum_(const uint8_t *command_data, uint8_t length) const
void dump_config() override
uint16_t get_16_bit_uint_(uint8_t start_index) const
sensor::Sensor * pm_2_5_sensor_
optional< bool > check_byte_() const
void publish_state(float state)
Publish a new state to the front-end.
bool read_available(F &&on_byte)
Same as read_available_chunks(), calling on_byte(uint8_t) once per byte.
void write_array(const uint8_t *data, size_t len)
ESPHOME_LOG_TAG(TAG, "pm1006")
constexpr uint8_t sum_bytes(const uint8_t *data, size_t len, uint8_t sum=0)
Add up the bytes of data with size len, truncated to 8 bits: the checksum many serial and IR protocol...