|
@ -18,16 +18,17 @@ class PMSX003Sensor : public BaseSensor { |
|
|
_pmsSerial = new SoftwareSerial(pin_rx, pin_tx, false, 256); |
|
|
_pmsSerial = new SoftwareSerial(pin_rx, pin_tx, false, 256); |
|
|
_pmsSerial->begin(9600); |
|
|
_pmsSerial->begin(9600); |
|
|
_pms = new PMS(* _pmsSerial); |
|
|
_pms = new PMS(* _pmsSerial); |
|
|
// _pmsSerial.begin(9600); |
|
|
|
|
|
|
|
|
_pms->passiveMode(); |
|
|
_pin_rx = pin_rx; |
|
|
_pin_rx = pin_rx; |
|
|
_pin_tx = pin_tx; |
|
|
_pin_tx = pin_tx; |
|
|
_count = 3; |
|
|
_count = 3; |
|
|
|
|
|
_startTime = millis(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// Descriptive name of the sensor |
|
|
// Descriptive name of the sensor |
|
|
String name() { |
|
|
String name() { |
|
|
char buffer[36]; |
|
|
|
|
|
snprintf(buffer, sizeof(buffer), "PMSX003 @ SwSerial RX: %i TX: %i", _pin_rx, _pin_tx); |
|
|
|
|
|
|
|
|
char buffer[28]; |
|
|
|
|
|
snprintf(buffer, sizeof(buffer), "PMSX003 @ SwSerial(%i,%i)", _pin_rx, _pin_tx); |
|
|
return String(buffer); |
|
|
return String(buffer); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -35,9 +36,11 @@ class PMSX003Sensor : public BaseSensor { |
|
|
String slot(unsigned char index) { |
|
|
String slot(unsigned char index) { |
|
|
if (index < _count) { |
|
|
if (index < _count) { |
|
|
_error = SENSOR_ERROR_OK; |
|
|
_error = SENSOR_ERROR_OK; |
|
|
if (index == 0) return String("PM 1.0"); |
|
|
|
|
|
if (index == 1) return String("PM 2.5"); |
|
|
|
|
|
if (index == 2) return String("PM 10"); |
|
|
|
|
|
|
|
|
char buffer[36]; |
|
|
|
|
|
if (index == 0) snprintf(buffer, sizeof(buffer), "PM1.0 @ PMSX003 @ SwSerial(%i,%i)", _pin_rx, _pin_tx); |
|
|
|
|
|
if (index == 1) snprintf(buffer, sizeof(buffer), "PM2.5 @ PMSX003 @ SwSerial(%i,%i)", _pin_rx, _pin_tx); |
|
|
|
|
|
if (index == 2) snprintf(buffer, sizeof(buffer), "PM10 @ PMSX003 @ SwSerial(%i,%i)", _pin_rx, _pin_tx); |
|
|
|
|
|
return String(buffer); |
|
|
} |
|
|
} |
|
|
_error = SENSOR_ERROR_OUT_OF_RANGE; |
|
|
_error = SENSOR_ERROR_OUT_OF_RANGE; |
|
|
return String(); |
|
|
return String(); |
|
@ -55,6 +58,23 @@ class PMSX003Sensor : public BaseSensor { |
|
|
return MAGNITUDE_NONE; |
|
|
return MAGNITUDE_NONE; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void pre() { |
|
|
|
|
|
if(millis() - _startTime > 30000) { |
|
|
|
|
|
_error = SENSOR_ERROR_OK; |
|
|
|
|
|
} else { |
|
|
|
|
|
_error = SENSOR_ERROR_WARM_UP; |
|
|
|
|
|
} |
|
|
|
|
|
_pms->requestRead(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void tick() { |
|
|
|
|
|
if(_pms->read(_data)) { |
|
|
|
|
|
_pm1dot0 = _data.PM_AE_UG_1_0; |
|
|
|
|
|
_pm2dot5 = _data.PM_AE_UG_2_5; |
|
|
|
|
|
_pm10 = _data.PM_AE_UG_10_0; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// Current value for slot # index |
|
|
// Current value for slot # index |
|
|
double value(unsigned char index) { |
|
|
double value(unsigned char index) { |
|
|
if (index < _count) { |
|
|
if (index < _count) { |
|
@ -66,15 +86,6 @@ class PMSX003Sensor : public BaseSensor { |
|
|
_error = SENSOR_ERROR_OUT_OF_RANGE; |
|
|
_error = SENSOR_ERROR_OUT_OF_RANGE; |
|
|
return 0; |
|
|
return 0; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void tick() { |
|
|
|
|
|
if(_pms->read(_data, 1000)) { |
|
|
|
|
|
// if (_pms.read(_data)) { |
|
|
|
|
|
_pm1dot0 = _data.PM_AE_UG_1_0; |
|
|
|
|
|
_pm2dot5 = _data.PM_AE_UG_2_5; |
|
|
|
|
|
_pm10 = _data.PM_AE_UG_10_0; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
protected: |
|
|
protected: |
|
|
unsigned int _pm1dot0; |
|
|
unsigned int _pm1dot0; |
|
@ -82,10 +93,9 @@ class PMSX003Sensor : public BaseSensor { |
|
|
unsigned int _pm10; |
|
|
unsigned int _pm10; |
|
|
unsigned int _pin_rx; |
|
|
unsigned int _pin_rx; |
|
|
unsigned int _pin_tx; |
|
|
unsigned int _pin_tx; |
|
|
|
|
|
unsigned long _startTime; |
|
|
SoftwareSerial * _pmsSerial; |
|
|
SoftwareSerial * _pmsSerial; |
|
|
PMS * _pms; |
|
|
PMS * _pms; |
|
|
// SoftwareSerial _pmsSerial; |
|
|
|
|
|
// PMS _pms; |
|
|
|
|
|
PMS::DATA _data; |
|
|
PMS::DATA _data; |
|
|
|
|
|
|
|
|
}; |
|
|
}; |