6static const char *
const TAG =
"pm1006";
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);
23 ESP_LOGV(TAG,
"sending measurement request");
24 this->
write_array(PM1006_REQUEST,
sizeof(PM1006_REQUEST));
31 if (!check.has_value()) {
34 this->data_index_ = 0;
37 ESP_LOGV(TAG,
"Byte %i of received data frame is invalid.", this->data_index_);
38 this->data_index_ = 0;
48 for (uint8_t i = 0; i <
length; i++) {
49 sum += command_data[i];
56 const uint8_t
byte = this->
data_[index];
59 if (index <
sizeof(PM1006_RESPONSE_HEADER)) {
60 return byte == PM1006_RESPONSE_HEADER[index];
69 if (index < (
sizeof(PM1006_RESPONSE_HEADER) + 16))
73 if (index == (
sizeof(PM1006_RESPONSE_HEADER) + 16)) {
76 ESP_LOGW(TAG,
"PM1006 checksum is wrong: %02x, expected zero",
checksum);
88 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.
void check_uart_settings(uint32_t baud_rate, uint8_t stop_bits=1, UARTParityOptions parity=UART_CONFIG_PARITY_NONE, uint8_t data_bits=8)
Check that the configuration of the UART bus matches the provided values and otherwise print a warnin...
bool read_byte(uint8_t *data)
void write_array(const uint8_t *data, size_t len)