diff --git a/sensors/SensorDSM501A.h b/sensors/SensorDSM501A.h index 395f594e..64e1177b 100644 --- a/sensors/SensorDSM501A.h +++ b/sensors/SensorDSM501A.h @@ -53,14 +53,16 @@ class SensorDSM501A: public Sensor { // define what to do during loop void onLoop(Child* child) { - if (child == children.get(1)) { - // get PM 1.0 - density of particles over 1 µm. - child->setValue((int)((_getPM(_pin_10)*0.0283168/100/1000) * (0.08205*_temperature)/0.01)); - } - if (child == children.get(2)) { - // get PM 2.5 density of particles over 2.5 µm. - child->setValue((int)_getPM(_pin_25)); - } + int ppm = -1; + // get PM 1.0 - density of particles over 1 µm. + if (child == children.get(1)) ppm = (int)(_getPM(_pin_10)); + // sleep before the next read + nodeManager.sleepOrWait(5000); + // get PM 2.5 density of particles over 2.5 µm. + if (child == children.get(2)) ppm = (int)(_getPM(_pin_25)); + // set the value if positive (e.g. negative = invalid read) + if (ppm > 0) child->setValue(ppm); + else debug(PSTR("!" LOG_SENSOR "READ\n")); }; // return PM concentration