From 610f161be7f67ac0ef50cf4331041baef45b571e Mon Sep 17 00:00:00 2001 From: Oscar Rovira Date: Sat, 16 Dec 2017 19:18:58 +0100 Subject: [PATCH] Begin with PMSx003 support --- code/.gitignore | 2 ++ code/espurna/config/general.h | 6 ++++++ code/espurna/config/hardware.h | 4 ++++ code/espurna/sensor.ino | 14 ++++++++++++++ code/espurna/sensors/BaseSensor.h | 4 ++++ 5 files changed, 30 insertions(+) diff --git a/code/.gitignore b/code/.gitignore index 7f05aa6e..a7e598ae 100644 --- a/code/.gitignore +++ b/code/.gitignore @@ -4,3 +4,5 @@ .piolibdeps .vscode/c_cpp_properties.json core_version.h +.pioenvs +.piolibdeps diff --git a/code/espurna/config/general.h b/code/espurna/config/general.h index 5a3bb2cd..1a1941dc 100644 --- a/code/espurna/config/general.h +++ b/code/espurna/config/general.h @@ -774,6 +774,9 @@ PROGMEM const char* const custom_reset_string[] = { #define SENSOR_POWER_DECIMALS 0 #define SENSOR_POWER_FACTOR_DECIMALS 0 #define SENSOR_ENERGY_DECIMALS 0 +#define SENSOR_PM1dot0_DECIMALS 0 +#define SENSOR_PM2dot5_DECIMALS 0 +#define SENSOR_PM10_DECIMALS 0 #define SENSOR_UNKNOWN_TOPIC "unknown" #define SENSOR_TEMPERATURE_TOPIC "temperature" @@ -787,6 +790,9 @@ PROGMEM const char* const custom_reset_string[] = { #define SENSOR_POWER_FACTOR_TOPIC "factor" #define SENSOR_ENERGY_TOPIC "energy" #define SENSOR_ENERGY_DELTA_TOPIC "energy_delta" +#define SENSOR_PM1dot0_TOPIC "pm1dot0" +#define SENSOR_PM2dot5_TOPIC "pm2dot5" +#define SENSOR_PM10_TOPIC "pm10" #define SENSOR_ANALOG_TOPIC "analog" #define SENSOR_EVENTS_TOPIC "events" diff --git a/code/espurna/config/hardware.h b/code/espurna/config/hardware.h index 6cf83532..9f51fca3 100644 --- a/code/espurna/config/hardware.h +++ b/code/espurna/config/hardware.h @@ -43,6 +43,10 @@ #define LED1_PIN 2 #define LED1_PIN_INVERSE 1 + #define PMSX003_SUPPORT true + #define PMS_RX_PIN 13 + #define PMS_TX_PIN 15 + #elif defined(WEMOS_D1_MINI_RELAYSHIELD) // Info diff --git a/code/espurna/sensor.ino b/code/espurna/sensor.ino index 30cf144b..f08a41ab 100644 --- a/code/espurna/sensor.ino +++ b/code/espurna/sensor.ino @@ -48,6 +48,9 @@ String _sensorTopic(magnitude_t type) { if (type == MAGNITUDE_POWER_FACTOR) return String(SENSOR_POWER_FACTOR_TOPIC); if (type == MAGNITUDE_ENERGY) return String(SENSOR_ENERGY_TOPIC); if (type == MAGNITUDE_ENERGY_DELTA) return String(SENSOR_ENERGY_DELTA_TOPIC); + if (type == MAGNITUDE_PM1dot0) return String(SENSOR_PM1dot0_TOPIC); + if (type == MAGNITUDE_PM2dot5) return String(SENSOR_PM2dot5_TOPIC); + if (type == MAGNITUDE_PM10) return String(SENSOR_PM10_TOPIC); if (type == MAGNITUDE_ANALOG) return String(SENSOR_ANALOG_TOPIC); if (type == MAGNITUDE_EVENTS) return String(SENSOR_EVENTS_TOPIC); return String(SENSOR_UNKNOWN_TOPIC); @@ -65,6 +68,9 @@ unsigned char _sensorDecimals(magnitude_t type) { if (type == MAGNITUDE_POWER_FACTOR) return SENSOR_POWER_FACTOR_DECIMALS; if (type == MAGNITUDE_ENERGY) return SENSOR_ENERGY_DECIMALS; if (type == MAGNITUDE_ENERGY_DELTA) return SENSOR_ENERGY_DECIMALS; + if (type == MAGNITUDE_PM1dot0) return SENSOR_PM1dot0_DECIMALS; + if (type == MAGNITUDE_PM2dot5) return SENSOR_PM2dot5_DECIMALS; + if (type == MAGNITUDE_PM10) return SENSOR_PM10_DECIMALS; if (type == MAGNITUDE_ANALOG) return SENSOR_ANALOG_DECIMALS; if (type == MAGNITUDE_EVENTS) return SENSOR_EVENTS_DECIMALS; return 0; @@ -80,6 +86,9 @@ String _sensorUnits(magnitude_t type) { if (type == MAGNITUDE_POWER_APPARENT) return String("W"); if (type == MAGNITUDE_POWER_REACTIVE) return String("W"); if (type == MAGNITUDE_POWER_FACTOR) return String("%"); + if (type == MAGNITUDE_PM1dot0) return String("µg/m3"); + if (type == MAGNITUDE_PM2dot5) return String("µg/m3"); + if (type == MAGNITUDE_PM10) return String("µg/m3"); if (type == MAGNITUDE_ENERGY) return String("J"); if (type == MAGNITUDE_ENERGY_DELTA) return String("J"); if (type == MAGNITUDE_EVENTS) return String("/m"); @@ -252,6 +261,11 @@ void sensorInit() { #include "sensors/EmonADS1115Sensor.h" sensorRegister(new EmonADS1115Sensor(EMON_ADS1115_I2C_ADDRESS, EMON_ADS1115_PORT_MASK, EMON_MAINS_VOLTAGE, EMON_ADS1115_ADC_BITS, EMON_ADS1115_REFERENCE_VOLTAGE, EMON_ADS1115_CURRENT_RATIO)); #endif + + #if PMSX003_SUPPORT + #include "sensors/PMSX003Sensor.h" + sensorRegister(new PMSX003Sensor(PMS_RX_PIN, PMS_TX_PIN)); + #endif #if COUNTER_SUPPORT if (_sensor_isr == 0xFF) { diff --git a/code/espurna/sensors/BaseSensor.h b/code/espurna/sensors/BaseSensor.h index 3e32bd2d..ba2b7d3f 100644 --- a/code/espurna/sensors/BaseSensor.h +++ b/code/espurna/sensors/BaseSensor.h @@ -23,6 +23,10 @@ typedef enum magnitude_t { MAGNITUDE_ENERGY_DELTA, MAGNITUDE_POWER_FACTOR, + MAGNITUDE_PM1dot0, + MAGNITUDE_PM2dot5, + MAGNITUDE_PM10, + MAGNITUDE_ANALOG, MAGNITUDE_EVENTS,