Skip to content
This repository has been archived by the owner on Sep 27, 2023. It is now read-only.

Ppd42 x #577

Open
wants to merge 77 commits into
base: dev
Choose a base branch
from
Open

Ppd42 x #577

wants to merge 77 commits into from

Conversation

pi4homez
Copy link

@pi4homez pi4homez commented Mar 31, 2019

Description:

Related issue (if applicable): fixes

Pull request in esphome with python changes (if applicable): esphome/esphome#
Pull request in esphome-docs with documentation (if applicable): esphome/esphome-docs#

Checklist:

  • [x ] The code change is tested and works locally.
  • [x ] The code change follows the standards

If user exposed functionality or configuration variables are added/changed:

@@ -13,7 +13,7 @@ lib_deps =
ESP Async [email protected]
[email protected]
[email protected]
ESPAsyncTCP@1.2.0
ESPAsyncTCP@1.1.3
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this.


namespace sensor {

class Ppd42xSensorComponent : public PollingSensorComponent {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This class shouldn't inherit from PollingSensorComponent but from PollingComponent. In your current design both PM10 and pm2.5 values will be published to the same sensor, which is wrong. Please see PMSx003 example for how to split the two values.

std::string Ppd42xSensorComponent::icon() { return "mdi:arrow-expand-vertical"; }

int8_t Ppd42xSensorComponent::accuracy_decimals() {
return 2; // cm precision
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale comment


float Ppd42xSensorComponent::get_setup_priority() const { return setup_priority::HARDWARE_LATE; }
std::string Ppd42xSensorComponent::unit_of_measurement() { return "µg/m³"; }
std::string Ppd42xSensorComponent::icon() { return "mdi:arrow-expand-vertical"; }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrong icon

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wich icon you recommend?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See other particulate matter sensors, for example pmsx003

src/esphome/sensor/ppd42x_sensor.cpp Outdated Show resolved Hide resolved
float result = Ppd42xSensorComponent::us_to_pm(this->timeout_us_, time_pm_10_0);
this->publish_state(result);
ESP_LOGD(TAG, "'%s' - Got PM10.0 Concentration: %.1f µg/m³", this->name_.c_str(), result);
this->publish_state(result);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't double publish

@OttoWinter
Copy link
Member

Your PR contains commits that are not part of this PR (see files tabs, changes are listed there that have nothing to do with this PR). This is due to an incorrect merge. Please see contributing guide for merging dev correctly.

this->timeout_us_);
uint32_t duration_pl_10_0 = pulseIn(this->pl_10_0_sensor_->pl_pin_->get_pin(),
uint8_t(!this->pl_10_0_sensor_->pl_pin_->is_inverted()),
this->timeout_us_);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't do this inside loop() - Since the timeout is ms this will slow down the entire esphome core loop. That's ok when it's only executed every so often, but not if it's done every loop cycle.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

got it, i will protect by update cycle

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefere to reuse what you did on pulse_count module with interruption, what is your advise?

this->lowpulseoccupancy_02_5_ = this->lowpulseoccupancy_02_5_ + duration_pl_02_5;
this->lowpulseoccupancy_10_0_ = this->lowpulseoccupancy_10_0_ + duration_pl_10_0;

if (now - this->starttime_ > this->timeout_us_) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're comparing a value in ms to one in us. Please just update and publish data in update

case PPD42X_TYPE: {
float pl_02_5_concentration = us_to_pl(this->lowpulseoccupancy_02_5_, this->timeout_us_);
float pl_10_0_concentration = us_to_pl(this->lowpulseoccupancy_10_0_, this->timeout_us_);
ESP_LOGD(TAG, "Got PM2.5 Concentration %f pcs/L, PM10.0 Concentration: %f pcs/L", pl_02_5_concentration,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ESP_LOGD(TAG, "Got PM2.5 Concentration %f pcs/L, PM10.0 Concentration: %f pcs/L", pl_02_5_concentration,
ESP_LOGD(TAG, "Got PM2.5 Concentration %.0f pcs/L, PM10.0 Concentration: %.0f pcs/L", pl_02_5_concentration,

this->pl_02_5_sensor_->publish_state(pl_02_5_concentration);
if (this->pl_10_0_sensor_ != nullptr)
this->pl_10_0_sensor_->publish_state(pl_10_0_concentration);
break;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the difference between these switch cases? They all look the same to me.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we may have only one sensor ? PM2.5 or PM10.0 or both

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I mean why do you differentiate between this->ctype_ ? All the switch cases look the same to me.

}
}
float PPD42XComponent::us_to_pl(uint32_t sample_length, uint32_t time_pm) {
float ratio = time_pm / (sample_length * 10.0f);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does this depend on the timeout value?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the recommended max value to listen to !

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean why does this calculation depend on the timeout? The sensor doesn't know which timeout we chose, so how can this calculation depend on the timeout value this->timeout_us_ we chose?

Copy link
Author

@pi4homez pi4homez Apr 8, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nop, the sensor send continuously data.
we cannot stay stuck too long to lisning the end of the signal, so we timeout...

uint32_t lowpulseoccupancy_10_0_{0};

uint32_t last_transmission_{0};
uint32_t ui_{60000};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this value for?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ui_ is the update interval, name too short ?

@pi4homez
Copy link
Author

pi4homez commented Apr 8, 2019

Hi Otto, can you please help to resolve this conflict? i do not know how to do it

Copy link
Author

@pi4homez pi4homez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

try to solve conflict :(

Copy link
Author

@pi4homez pi4homez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok?

Copy link
Author

@pi4homez pi4homez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK for merge?

conflict
@cyberjunky
Copy link

Any chance this gets merged soon?

@vespadj
Copy link

vespadj commented Jun 4, 2021

I'm also waiting for this merge.
As workaround I'm using pulse_width / duty_cycle
but the output value is in % and it's low meaningful.
PPD42 output is LPO (low pulse occupacy), so
for 0=clean and 0> pullution

pin:
      number: GPIO13 # your input
      inverted: true

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants