7 static const char *
const TAG =
"pm1006";
9 static const uint8_t PM1006_RESPONSE_HEADER[] = {0x16, 0x11, 0x0B};
10 static const uint8_t PM1006_REQUEST[] = {0x11, 0x02, 0x0B, 0x01, 0xE1};
17 ESP_LOGCONFIG(TAG,
"PM1006:");
19 LOG_UPDATE_INTERVAL(
this);
24 ESP_LOGV(TAG,
"sending measurement request");
25 this->
write_array(PM1006_REQUEST,
sizeof(PM1006_REQUEST));
32 if (!check.has_value()) {
35 this->data_index_ = 0;
38 ESP_LOGV(TAG,
"Byte %i of received data frame is invalid.", this->data_index_);
39 this->data_index_ = 0;
51 for (uint8_t i = 0; i <
length; i++) {
52 sum += command_data[i];
59 uint8_t byte = this->
data_[index];
62 if (index <
sizeof(PM1006_RESPONSE_HEADER)) {
63 return byte == PM1006_RESPONSE_HEADER[index];
72 if (index < (
sizeof(PM1006_RESPONSE_HEADER) + 16))
76 if (index == (
sizeof(PM1006_RESPONSE_HEADER) + 16)) {
79 ESP_LOGW(TAG,
"PM1006 checksum is wrong: %02x, expected zero", checksum);
91 ESP_LOGD(TAG,
"Got PM2.5 Concentration: %d µg/m³", pm_2_5_concentration);
const float DATA
For components that import data from directly connected sensors like DHT.
void write_array(const uint8_t *data, size_t len)
sensor::Sensor * pm_2_5_sensor_
void dump_config() override
uint16_t get_16_bit_uint_(uint8_t start_index) const
float get_setup_priority() const override
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 publish_state(float state)
Publish a new state to the front-end.
constexpr uint16_t encode_uint16(uint8_t msb, uint8_t lsb)
Encode a 16-bit value given the most and least significant byte.
uint8_t pm1006_checksum_(const uint8_t *command_data, uint8_t length) const
optional< bool > check_byte_() const
Implementation of SPI Controller mode.