7 static const char *
const TAG =
"pmsx003";
51 const uint32_t now =
millis();
105 if (!check.has_value()) {
108 this->data_index_ = 0;
110 }
else if (!*check) {
112 this->data_index_ = 0;
122 uint8_t byte = this->
data_[index];
135 bool length_matches =
false;
136 switch (this->
type_) {
138 length_matches = payload_length == 28 || payload_length == 20;
142 length_matches = payload_length == 28;
145 length_matches = payload_length == 36;
149 if (!length_matches) {
150 ESP_LOGW(TAG,
"PMSX003 length %u doesn't match. Are you using the correct PMSX003 type?", payload_length);
157 uint8_t total_size = 4 + payload_length;
159 if (index < total_size - 1)
164 for (uint8_t i = 0; i < total_size - 2; i++)
165 checksum += this->
data_[i];
168 if (checksum != check) {
169 ESP_LOGW(TAG,
"PMSX003 checksum mismatch! 0x%02X!=0x%02X", checksum, check);
185 sum += this->
data_[i];
187 this->
data_[data_index_++] = (sum >> 8) & 0xFF;
188 this->
data_[data_index_++] = (sum >> 0) & 0xFF;
192 this->data_index_ = 0;
196 switch (this->
type_) {
201 ESP_LOGD(TAG,
"Got Temperature: %.1f°C, Humidity: %.1f%%", temperature, humidity);
212 ESP_LOGD(TAG,
"Got Formaldehyde: %u µg/m^3", formaldehyde);
235 "Got PM1.0 Concentration: %u µg/m^3, PM2.5 Concentration %u µg/m^3, PM10.0 Concentration: %u µg/m^3",
236 pm_1_0_concentration, pm_2_5_concentration, pm_10_0_concentration);
286 "Got PM1.0 Concentration: %u µg/m^3, PM2.5 Concentration %u µg/m^3, PM10.0 Concentration: %u µg/m^3, " 287 "Temperature: %.1f°C, Humidity: %.1f%%",
288 pm_1_0_concentration, pm_2_5_concentration, pm_10_0_concentration, temperature, humidity);
331 return (uint16_t(this->
data_[start_index]) << 8) | uint16_t(this->
data_[start_index + 1]);
334 ESP_LOGCONFIG(TAG,
"PMSX003:");
const float DATA
For components that import data from directly connected sensors like DHT.
sensor::Sensor * pm_10_0_sensor_
sensor::Sensor * pm_particles_50um_sensor_
void write_byte(uint8_t data)
sensor::Sensor * pm_1_0_std_sensor_
uint32_t update_interval_
sensor::Sensor * pm_10_0_std_sensor_
sensor::Sensor * pm_2_5_std_sensor_
void set_pm_2_5_std_sensor(sensor::Sensor *pm_2_5_std_sensor)
void set_pm_particles_10um_sensor(sensor::Sensor *pm_particles_10um_sensor)
void set_pm_2_5_sensor(sensor::Sensor *pm_2_5_sensor)
sensor::Sensor * pm_particles_10um_sensor_
void set_pm_particles_100um_sensor(sensor::Sensor *pm_particles_100um_sensor)
sensor::Sensor * pm_particles_25um_sensor_
uint32_t IRAM_ATTR HOT millis()
void set_humidity_sensor(sensor::Sensor *humidity_sensor)
sensor::Sensor * formaldehyde_sensor_
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...
sensor::Sensor * pm_2_5_sensor_
sensor::Sensor * pm_particles_03um_sensor_
uint32_t last_transmission_
bool read_byte(uint8_t *data)
void set_pm_10_0_std_sensor(sensor::Sensor *pm_10_0_std_sensor)
void status_clear_warning()
sensor::Sensor * pm_1_0_sensor_
void publish_state(float state)
Publish a new state to the front-end.
float get_setup_priority() const override
sensor::Sensor * temperature_sensor_
void dump_config() override
uint16_t get_16_bit_uint_(uint8_t start_index)
void set_pm_particles_50um_sensor(sensor::Sensor *pm_particles_50um_sensor)
optional< bool > check_byte_()
sensor::Sensor * pm_particles_05um_sensor_
void set_pm_1_0_sensor(sensor::Sensor *pm_1_0_sensor)
sensor::Sensor * pm_particles_100um_sensor_
sensor::Sensor * humidity_sensor_
void set_pm_particles_25um_sensor(sensor::Sensor *pm_particles_25um_sensor)
void send_command_(uint8_t cmd, uint16_t data)
Implementation of SPI Controller mode.
Base-class for all sensors.
void set_pm_particles_03um_sensor(sensor::Sensor *pm_particles_03um_sensor)
void set_formaldehyde_sensor(sensor::Sensor *formaldehyde_sensor)
void set_pm_10_0_sensor(sensor::Sensor *pm_10_0_sensor)
void set_pm_1_0_std_sensor(sensor::Sensor *pm_1_0_std_sensor)
void set_temperature_sensor(sensor::Sensor *temperature_sensor)
void set_pm_particles_05um_sensor(sensor::Sensor *pm_particles_05um_sensor)