Skip to content

Commit

Permalink
Add support for showing number of particles on PMSX003 devices
Browse files Browse the repository at this point in the history
  • Loading branch information
ruimarinho committed Nov 2, 2018
1 parent e2641b9 commit 29e30c6
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 19 deletions.
16 changes: 14 additions & 2 deletions code/espurna/config/progmem.h
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,8 @@ PROGMEM const unsigned char magnitude_decimals[] = {
1, 0, 2, // THP
3, 0, 0, 0, 0, 0, 0, 0, // Power decimals
0, 0, 0, // analog, digital, event
0, 0, 0, // PM
0, 0, 0, // PM1.0, PM2.5, PM10
0, 0, 0, 0, 0, 0, // Particles count
0, 0, 3, 3, 0,
4, 4, // Geiger Counter decimals
0,
Expand All @@ -256,6 +257,12 @@ PROGMEM const char magnitude_event_topic[] = "event";
PROGMEM const char magnitude_pm1dot0_topic[] = "pm1dot0";
PROGMEM const char magnitude_pm2dot5_topic[] = "pm2dot5";
PROGMEM const char magnitude_pm10_topic[] = "pm10";
PROGMEM const char magnitude_particles_0dot3_topic[] = "particles0dot3";
PROGMEM const char magnitude_particles_0dot5_topic[] = "particles0dot5";
PROGMEM const char magnitude_particles_1_topic[] = "particles1";
PROGMEM const char magnitude_particles_2dot5_topic[] = "particles2dot5";
PROGMEM const char magnitude_particles_5_topic[] = "particles5";
PROGMEM const char magnitude_particles_10_topic[] = "particles10";
PROGMEM const char magnitude_co2_topic[] = "co2";
PROGMEM const char magnitude_lux_topic[] = "lux";
PROGMEM const char magnitude_uv_topic[] = "uv";
Expand All @@ -275,6 +282,8 @@ PROGMEM const char* const magnitude_topics[] = {
magnitude_power_factor_topic, magnitude_energy_topic, magnitude_energy_delta_topic,
magnitude_analog_topic, magnitude_digital_topic, magnitude_event_topic,
magnitude_pm1dot0_topic, magnitude_pm2dot5_topic, magnitude_pm10_topic,
magnitude_particles_0dot3_topic, magnitude_particles_0dot5_topic, magnitude_particles_1_topic,
magnitude_particles_2dot5_topic, magnitude_particles_5_topic, magnitude_particles_10_topic,
magnitude_co2_topic, magnitude_lux_topic, magnitude_uv_topic,
magnitude_distance_topic, magnitude_hcho_topic,
magnitude_geiger_cpm_topic, magnitude_geiger_sv_topic,
Expand Down Expand Up @@ -302,6 +311,7 @@ PROGMEM const char magnitude_mgm3[] = "mg/m³";
PROGMEM const char magnitude_geiger_cpm[] = "cpm"; // Counts per Minute: Unit of local dose rate (Geiger counting)
PROGMEM const char magnitude_geiger_sv[] = "µSv/h"; // µSievert per hour: 2nd unit of local dose rate (Geiger counting)
PROGMEM const char magnitude_resistance[] = "ohm";
PROGMEM const char magnitude_particles_l[] = "particles/l";


PROGMEM const char* const magnitude_units[] = {
Expand All @@ -310,7 +320,9 @@ PROGMEM const char* const magnitude_units[] = {
magnitude_watts, magnitude_watts, magnitude_watts,
magnitude_percentage, magnitude_joules, magnitude_joules,
magnitude_empty, magnitude_empty, magnitude_empty,
magnitude_ugm3, magnitude_ugm3, magnitude_ugm3,
magnitude_ugm3, magnitude_ugm3, magnitude_ugm3, // PM1.0, PM2.5, PM10
magnitude_particles_l, magnitude_particles_l, magnitude_particles_l, // Particles
magnitude_particles_l, magnitude_particles_l, magnitude_particles_l, // Particles
magnitude_ppm, magnitude_lux, magnitude_uv,
magnitude_distance, magnitude_mgm3,
magnitude_geiger_cpm, magnitude_geiger_sv, // Geiger counter units
Expand Down
30 changes: 18 additions & 12 deletions code/espurna/config/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -301,17 +301,23 @@
#define MAGNITUDE_EVENT 14
#define MAGNITUDE_PM1dot0 15
#define MAGNITUDE_PM2dot5 16
#define MAGNITUDE_PM10 17
#define MAGNITUDE_CO2 18
#define MAGNITUDE_LUX 19
#define MAGNITUDE_UV 20
#define MAGNITUDE_DISTANCE 21
#define MAGNITUDE_HCHO 22
#define MAGNITUDE_GEIGER_CPM 23
#define MAGNITUDE_GEIGER_SIEVERT 24
#define MAGNITUDE_COUNT 25
#define MAGNITUDE_NO2 26
#define MAGNITUDE_CO 27
#define MAGNITUDE_RESISTANCE 28
#define MAGNITUDE_PARTICLES_0dot3 17
#define MAGNITUDE_PARTICLES_0dot5 18
#define MAGNITUDE_PARTICLES_1 19
#define MAGNITUDE_PARTICLES_2dot5 20
#define MAGNITUDE_PARTICLES_5 21
#define MAGNITUDE_PARTICLES_10 22
#define MAGNITUDE_PM10 23
#define MAGNITUDE_CO2 24
#define MAGNITUDE_LUX 25
#define MAGNITUDE_UV 26
#define MAGNITUDE_DISTANCE 27
#define MAGNITUDE_HCHO 28
#define MAGNITUDE_GEIGER_CPM 29
#define MAGNITUDE_GEIGER_SIEVERT 30
#define MAGNITUDE_COUNT 31
#define MAGNITUDE_NO2 32
#define MAGNITUDE_CO 33
#define MAGNITUDE_RESISTANCE 34

#define MAGNITUDE_MAX 29
2 changes: 1 addition & 1 deletion code/espurna/sensor.ino
Original file line number Diff line number Diff line change
Expand Up @@ -1114,7 +1114,7 @@ String magnitudeTopicIndex(unsigned char index) {


String magnitudeUnits(unsigned char type) {
char buffer[8] = {0};
char buffer[14] = {0};
if (type < MAGNITUDE_MAX) {
if ((type == MAGNITUDE_TEMPERATURE) && (_sensor_temperature_units == TMP_FAHRENHEIT)) {
strncpy_P(buffer, magnitude_fahrenheit, sizeof(buffer));
Expand Down
27 changes: 24 additions & 3 deletions code/espurna/sensors/PMSX003Sensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,31 @@
#define PMS_TYPE_5003ST 3

// Sensor type specified data
#define PMS_SLOT_MAX 4
#define PMS_SLOT_MAX 9
#define PMS_DATA_MAX 17
const static struct {
const char *name;
unsigned char data_count;
unsigned char slot_count;
unsigned char slot_types[PMS_SLOT_MAX];
} pms_specs[] = {
{"PMSX003", 13, 3, {MAGNITUDE_PM1dot0, MAGNITUDE_PM2dot5, MAGNITUDE_PM10}},
{"PMSX003_9", 9, 3, {MAGNITUDE_PM1dot0, MAGNITUDE_PM2dot5, MAGNITUDE_PM10}},
{"PMSX003", 13, 9, {
MAGNITUDE_PM1dot0,
MAGNITUDE_PM2dot5,
MAGNITUDE_PM10,
MAGNITUDE_PARTICLES_0dot3,
MAGNITUDE_PARTICLES_0dot5,
MAGNITUDE_PARTICLES_1,
MAGNITUDE_PARTICLES_2dot5,
MAGNITUDE_PARTICLES_5,
MAGNITUDE_PARTICLES_10
}
},
{"PMSX003_9", 9, 3, {
MAGNITUDE_PM1dot0,
MAGNITUDE_PM2dot5,
MAGNITUDE_PM10
}},
{"PMS5003T", 13, 3, {MAGNITUDE_PM2dot5, MAGNITUDE_TEMPERATURE, MAGNITUDE_HUMIDITY}},
{"PMS5003ST", 17, 4, {MAGNITUDE_PM2dot5, MAGNITUDE_TEMPERATURE, MAGNITUDE_HUMIDITY, MAGNITUDE_HCHO}}
};
Expand Down Expand Up @@ -314,6 +329,12 @@ class PMSX003Sensor : public BaseSensor, PMSX003 {
_slot_values[0] = data[3];
_slot_values[1] = data[4];
_slot_values[2] = data[5];
_slot_values[3] = data[6] * 10; // convert particles per 0.1L of air to 1L
_slot_values[4] = data[7] * 10; // convert particles per 0.1L of air to 1L
_slot_values[5] = data[8] * 10; // convert particles per 0.1L of air to 1L
_slot_values[6] = data[9] * 10; // convert particles per 0.1L of air to 1L
_slot_values[7] = data[10] * 10; // convert particles per 0.1L of air to 1L
_slot_values[8] = data[11] * 10; // convert particles per 0.1L of air to 1L
}
}

Expand Down
5 changes: 4 additions & 1 deletion code/html/custom.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@ function magnitudeType(type) {
"Current", "Voltage", "Active Power", "Apparent Power",
"Reactive Power", "Power Factor", "Energy", "Energy (delta)",
"Analog", "Digital", "Event",
"PM1.0", "PM2.5", "PM10", "CO2", "Lux", "UV", "Distance" , "HCHO",
"PM1.0", "PM2.5", "PM10",
"Particles ≧0.3 ﹤0.5", "Particles ≧0.5 ﹤1", "Particles ≧1 ﹤2.5 ",
"Particles ≧2.5 ﹤5", "Particles ≧5 ﹤10", "Particles ≧10",
"CO2", "Lux", "UV", "Distance" , "HCHO",
"Local Dose Rate", "Local Dose Rate",
"Count",
"NO2", "CO", "Resistance"
Expand Down

0 comments on commit 29e30c6

Please sign in to comment.