Skip to content

Commit 29e30c6

Browse files
committed
Add support for showing number of particles on PMSX003 devices
1 parent e2641b9 commit 29e30c6

File tree

5 files changed

+61
-19
lines changed

5 files changed

+61
-19
lines changed

code/espurna/config/progmem.h

+14-2
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,8 @@ PROGMEM const unsigned char magnitude_decimals[] = {
231231
1, 0, 2, // THP
232232
3, 0, 0, 0, 0, 0, 0, 0, // Power decimals
233233
0, 0, 0, // analog, digital, event
234-
0, 0, 0, // PM
234+
0, 0, 0, // PM1.0, PM2.5, PM10
235+
0, 0, 0, 0, 0, 0, // Particles count
235236
0, 0, 3, 3, 0,
236237
4, 4, // Geiger Counter decimals
237238
0,
@@ -256,6 +257,12 @@ PROGMEM const char magnitude_event_topic[] = "event";
256257
PROGMEM const char magnitude_pm1dot0_topic[] = "pm1dot0";
257258
PROGMEM const char magnitude_pm2dot5_topic[] = "pm2dot5";
258259
PROGMEM const char magnitude_pm10_topic[] = "pm10";
260+
PROGMEM const char magnitude_particles_0dot3_topic[] = "particles0dot3";
261+
PROGMEM const char magnitude_particles_0dot5_topic[] = "particles0dot5";
262+
PROGMEM const char magnitude_particles_1_topic[] = "particles1";
263+
PROGMEM const char magnitude_particles_2dot5_topic[] = "particles2dot5";
264+
PROGMEM const char magnitude_particles_5_topic[] = "particles5";
265+
PROGMEM const char magnitude_particles_10_topic[] = "particles10";
259266
PROGMEM const char magnitude_co2_topic[] = "co2";
260267
PROGMEM const char magnitude_lux_topic[] = "lux";
261268
PROGMEM const char magnitude_uv_topic[] = "uv";
@@ -275,6 +282,8 @@ PROGMEM const char* const magnitude_topics[] = {
275282
magnitude_power_factor_topic, magnitude_energy_topic, magnitude_energy_delta_topic,
276283
magnitude_analog_topic, magnitude_digital_topic, magnitude_event_topic,
277284
magnitude_pm1dot0_topic, magnitude_pm2dot5_topic, magnitude_pm10_topic,
285+
magnitude_particles_0dot3_topic, magnitude_particles_0dot5_topic, magnitude_particles_1_topic,
286+
magnitude_particles_2dot5_topic, magnitude_particles_5_topic, magnitude_particles_10_topic,
278287
magnitude_co2_topic, magnitude_lux_topic, magnitude_uv_topic,
279288
magnitude_distance_topic, magnitude_hcho_topic,
280289
magnitude_geiger_cpm_topic, magnitude_geiger_sv_topic,
@@ -302,6 +311,7 @@ PROGMEM const char magnitude_mgm3[] = "mg/m³";
302311
PROGMEM const char magnitude_geiger_cpm[] = "cpm"; // Counts per Minute: Unit of local dose rate (Geiger counting)
303312
PROGMEM const char magnitude_geiger_sv[] = "µSv/h"; // µSievert per hour: 2nd unit of local dose rate (Geiger counting)
304313
PROGMEM const char magnitude_resistance[] = "ohm";
314+
PROGMEM const char magnitude_particles_l[] = "particles/l";
305315

306316

307317
PROGMEM const char* const magnitude_units[] = {
@@ -310,7 +320,9 @@ PROGMEM const char* const magnitude_units[] = {
310320
magnitude_watts, magnitude_watts, magnitude_watts,
311321
magnitude_percentage, magnitude_joules, magnitude_joules,
312322
magnitude_empty, magnitude_empty, magnitude_empty,
313-
magnitude_ugm3, magnitude_ugm3, magnitude_ugm3,
323+
magnitude_ugm3, magnitude_ugm3, magnitude_ugm3, // PM1.0, PM2.5, PM10
324+
magnitude_particles_l, magnitude_particles_l, magnitude_particles_l, // Particles
325+
magnitude_particles_l, magnitude_particles_l, magnitude_particles_l, // Particles
314326
magnitude_ppm, magnitude_lux, magnitude_uv,
315327
magnitude_distance, magnitude_mgm3,
316328
magnitude_geiger_cpm, magnitude_geiger_sv, // Geiger counter units

code/espurna/config/types.h

+18-12
Original file line numberDiff line numberDiff line change
@@ -301,17 +301,23 @@
301301
#define MAGNITUDE_EVENT 14
302302
#define MAGNITUDE_PM1dot0 15
303303
#define MAGNITUDE_PM2dot5 16
304-
#define MAGNITUDE_PM10 17
305-
#define MAGNITUDE_CO2 18
306-
#define MAGNITUDE_LUX 19
307-
#define MAGNITUDE_UV 20
308-
#define MAGNITUDE_DISTANCE 21
309-
#define MAGNITUDE_HCHO 22
310-
#define MAGNITUDE_GEIGER_CPM 23
311-
#define MAGNITUDE_GEIGER_SIEVERT 24
312-
#define MAGNITUDE_COUNT 25
313-
#define MAGNITUDE_NO2 26
314-
#define MAGNITUDE_CO 27
315-
#define MAGNITUDE_RESISTANCE 28
304+
#define MAGNITUDE_PARTICLES_0dot3 17
305+
#define MAGNITUDE_PARTICLES_0dot5 18
306+
#define MAGNITUDE_PARTICLES_1 19
307+
#define MAGNITUDE_PARTICLES_2dot5 20
308+
#define MAGNITUDE_PARTICLES_5 21
309+
#define MAGNITUDE_PARTICLES_10 22
310+
#define MAGNITUDE_PM10 23
311+
#define MAGNITUDE_CO2 24
312+
#define MAGNITUDE_LUX 25
313+
#define MAGNITUDE_UV 26
314+
#define MAGNITUDE_DISTANCE 27
315+
#define MAGNITUDE_HCHO 28
316+
#define MAGNITUDE_GEIGER_CPM 29
317+
#define MAGNITUDE_GEIGER_SIEVERT 30
318+
#define MAGNITUDE_COUNT 31
319+
#define MAGNITUDE_NO2 32
320+
#define MAGNITUDE_CO 33
321+
#define MAGNITUDE_RESISTANCE 34
316322

317323
#define MAGNITUDE_MAX 29

code/espurna/sensor.ino

+1-1
Original file line numberDiff line numberDiff line change
@@ -1114,7 +1114,7 @@ String magnitudeTopicIndex(unsigned char index) {
11141114

11151115

11161116
String magnitudeUnits(unsigned char type) {
1117-
char buffer[8] = {0};
1117+
char buffer[14] = {0};
11181118
if (type < MAGNITUDE_MAX) {
11191119
if ((type == MAGNITUDE_TEMPERATURE) && (_sensor_temperature_units == TMP_FAHRENHEIT)) {
11201120
strncpy_P(buffer, magnitude_fahrenheit, sizeof(buffer));

code/espurna/sensors/PMSX003Sensor.h

+24-3
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,31 @@
2424
#define PMS_TYPE_5003ST 3
2525

2626
// Sensor type specified data
27-
#define PMS_SLOT_MAX 4
27+
#define PMS_SLOT_MAX 9
2828
#define PMS_DATA_MAX 17
2929
const static struct {
3030
const char *name;
3131
unsigned char data_count;
3232
unsigned char slot_count;
3333
unsigned char slot_types[PMS_SLOT_MAX];
3434
} pms_specs[] = {
35-
{"PMSX003", 13, 3, {MAGNITUDE_PM1dot0, MAGNITUDE_PM2dot5, MAGNITUDE_PM10}},
36-
{"PMSX003_9", 9, 3, {MAGNITUDE_PM1dot0, MAGNITUDE_PM2dot5, MAGNITUDE_PM10}},
35+
{"PMSX003", 13, 9, {
36+
MAGNITUDE_PM1dot0,
37+
MAGNITUDE_PM2dot5,
38+
MAGNITUDE_PM10,
39+
MAGNITUDE_PARTICLES_0dot3,
40+
MAGNITUDE_PARTICLES_0dot5,
41+
MAGNITUDE_PARTICLES_1,
42+
MAGNITUDE_PARTICLES_2dot5,
43+
MAGNITUDE_PARTICLES_5,
44+
MAGNITUDE_PARTICLES_10
45+
}
46+
},
47+
{"PMSX003_9", 9, 3, {
48+
MAGNITUDE_PM1dot0,
49+
MAGNITUDE_PM2dot5,
50+
MAGNITUDE_PM10
51+
}},
3752
{"PMS5003T", 13, 3, {MAGNITUDE_PM2dot5, MAGNITUDE_TEMPERATURE, MAGNITUDE_HUMIDITY}},
3853
{"PMS5003ST", 17, 4, {MAGNITUDE_PM2dot5, MAGNITUDE_TEMPERATURE, MAGNITUDE_HUMIDITY, MAGNITUDE_HCHO}}
3954
};
@@ -314,6 +329,12 @@ class PMSX003Sensor : public BaseSensor, PMSX003 {
314329
_slot_values[0] = data[3];
315330
_slot_values[1] = data[4];
316331
_slot_values[2] = data[5];
332+
_slot_values[3] = data[6] * 10; // convert particles per 0.1L of air to 1L
333+
_slot_values[4] = data[7] * 10; // convert particles per 0.1L of air to 1L
334+
_slot_values[5] = data[8] * 10; // convert particles per 0.1L of air to 1L
335+
_slot_values[6] = data[9] * 10; // convert particles per 0.1L of air to 1L
336+
_slot_values[7] = data[10] * 10; // convert particles per 0.1L of air to 1L
337+
_slot_values[8] = data[11] * 10; // convert particles per 0.1L of air to 1L
317338
}
318339
}
319340

code/html/custom.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,10 @@ function magnitudeType(type) {
6161
"Current", "Voltage", "Active Power", "Apparent Power",
6262
"Reactive Power", "Power Factor", "Energy", "Energy (delta)",
6363
"Analog", "Digital", "Event",
64-
"PM1.0", "PM2.5", "PM10", "CO2", "Lux", "UV", "Distance" , "HCHO",
64+
"PM1.0", "PM2.5", "PM10",
65+
"Particles ≧0.3 ﹤0.5", "Particles ≧0.5 ﹤1", "Particles ≧1 ﹤2.5 ",
66+
"Particles ≧2.5 ﹤5", "Particles ≧5 ﹤10", "Particles ≧10",
67+
"CO2", "Lux", "UV", "Distance" , "HCHO",
6568
"Local Dose Rate", "Local Dose Rate",
6669
"Count",
6770
"NO2", "CO", "Resistance"

0 commit comments

Comments
 (0)