Skip to content

Commit fa1a11d

Browse files
committed
Add support for showing number of particles on PMSX003 devices
1 parent b497cc8 commit fa1a11d

File tree

5 files changed

+80
-38
lines changed

5 files changed

+80
-38
lines changed

code/espurna/config/progmem.h

+17-5
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,8 @@ PROGMEM const unsigned char magnitude_decimals[] = {
210210
1, 0, 2, // THP
211211
3, 0, 0, 0, 0, 0, 0, 0, // Power decimals
212212
0, 0, 0, // analog, digital, event
213-
0, 0, 0, // PM
213+
0, 0, 0, // PM1.0, PM2.5, PM10
214+
0, 0, 0, 0, 0, 0, // Particles count
214215
0, 0, 3, 3, 0,
215216
4, 4, // Geiger Counter decimals
216217
0
@@ -234,6 +235,12 @@ PROGMEM const char magnitude_event_topic[] = "event";
234235
PROGMEM const char magnitude_pm1dot0_topic[] = "pm1dot0";
235236
PROGMEM const char magnitude_pm2dot5_topic[] = "pm2dot5";
236237
PROGMEM const char magnitude_pm10_topic[] = "pm10";
238+
PROGMEM const char magnitude_particles_0dot3_topic[] = "particles0dot3";
239+
PROGMEM const char magnitude_particles_0dot5_topic[] = "particles0dot5";
240+
PROGMEM const char magnitude_particles_1_topic[] = "particles1";
241+
PROGMEM const char magnitude_particles_2dot5_topic[] = "particles2dot5";
242+
PROGMEM const char magnitude_particles_5_topic[] = "particles5";
243+
PROGMEM const char magnitude_particles_10_topic[] = "particles10";
237244
PROGMEM const char magnitude_co2_topic[] = "co2";
238245
PROGMEM const char magnitude_lux_topic[] = "lux";
239246
PROGMEM const char magnitude_uv_topic[] = "uv";
@@ -250,6 +257,8 @@ PROGMEM const char* const magnitude_topics[] = {
250257
magnitude_power_factor_topic, magnitude_energy_topic, magnitude_energy_delta_topic,
251258
magnitude_analog_topic, magnitude_digital_topic, magnitude_event_topic,
252259
magnitude_pm1dot0_topic, magnitude_pm2dot5_topic, magnitude_pm10_topic,
260+
magnitude_particles_0dot3_topic, magnitude_particles_0dot5_topic, magnitude_particles_1_topic,
261+
magnitude_particles_2dot5_topic, magnitude_particles_5_topic, magnitude_particles_10_topic,
253262
magnitude_co2_topic, magnitude_lux_topic, magnitude_uv_topic,
254263
magnitude_distance_topic, magnitude_hcho_topic,
255264
magnitude_geiger_cpm_topic, magnitude_geiger_sv_topic,
@@ -273,8 +282,9 @@ PROGMEM const char magnitude_lux[] = "lux";
273282
PROGMEM const char magnitude_uv[] = "uv";
274283
PROGMEM const char magnitude_distance[] = "m";
275284
PROGMEM const char magnitude_mgm3[] = "mg/m³";
276-
PROGMEM const char magnitude_geiger_cpm[] = "cpm"; // Counts per Minute: Unit of local dose rate (Geiger counting)
277-
PROGMEM const char magnitude_geiger_sv[] = "µSv/h"; // µSievert per hour: 2nd unit of local dose rate (Geiger counting)
285+
PROGMEM const char magnitude_geiger_cpm[] = "cpm"; // Counts per Minute: Unit of local dose rate (Geiger counting)
286+
PROGMEM const char magnitude_geiger_sv[] = "µSv/h"; // µSievert per hour: 2nd unit of local dose rate (Geiger counting)
287+
PROGMEM const char magnitude_particles_l[] = "particles/l";
278288

279289

280290
PROGMEM const char* const magnitude_units[] = {
@@ -283,10 +293,12 @@ PROGMEM const char* const magnitude_units[] = {
283293
magnitude_watts, magnitude_watts, magnitude_watts,
284294
magnitude_percentage, magnitude_joules, magnitude_joules,
285295
magnitude_empty, magnitude_empty, magnitude_empty,
286-
magnitude_ugm3, magnitude_ugm3, magnitude_ugm3,
296+
magnitude_ugm3, magnitude_ugm3, magnitude_ugm3, // PM1.0, PM2.5, PM10
297+
magnitude_particles_l, magnitude_particles_l, magnitude_particles_l, // Particles
298+
magnitude_particles_l, magnitude_particles_l, magnitude_particles_l, // Particles
287299
magnitude_ppm, magnitude_lux, magnitude_uv,
288300
magnitude_distance, magnitude_mgm3,
289-
magnitude_geiger_cpm, magnitude_geiger_sv, // Geiger counter units
301+
magnitude_geiger_cpm, magnitude_geiger_sv, // Geiger counter units
290302
magnitude_empty
291303
};
292304

code/espurna/config/types.h

+34-28
Original file line numberDiff line numberDiff line change
@@ -274,31 +274,37 @@
274274
// Magnitudes
275275
//--------------------------------------------------------------------------------
276276

277-
#define MAGNITUDE_NONE 0
278-
#define MAGNITUDE_TEMPERATURE 1
279-
#define MAGNITUDE_HUMIDITY 2
280-
#define MAGNITUDE_PRESSURE 3
281-
#define MAGNITUDE_CURRENT 4
282-
#define MAGNITUDE_VOLTAGE 5
283-
#define MAGNITUDE_POWER_ACTIVE 6
284-
#define MAGNITUDE_POWER_APPARENT 7
285-
#define MAGNITUDE_POWER_REACTIVE 8
286-
#define MAGNITUDE_POWER_FACTOR 9
287-
#define MAGNITUDE_ENERGY 10
288-
#define MAGNITUDE_ENERGY_DELTA 11
289-
#define MAGNITUDE_ANALOG 12
290-
#define MAGNITUDE_DIGITAL 13
291-
#define MAGNITUDE_EVENT 14
292-
#define MAGNITUDE_PM1dot0 15
293-
#define MAGNITUDE_PM2dot5 16
294-
#define MAGNITUDE_PM10 17
295-
#define MAGNITUDE_CO2 18
296-
#define MAGNITUDE_LUX 19
297-
#define MAGNITUDE_UV 20
298-
#define MAGNITUDE_DISTANCE 21
299-
#define MAGNITUDE_HCHO 22
300-
#define MAGNITUDE_GEIGER_CPM 23
301-
#define MAGNITUDE_GEIGER_SIEVERT 24
302-
#define MAGNITUDE_COUNT 25
303-
304-
#define MAGNITUDE_MAX 26
277+
#define MAGNITUDE_NONE 0
278+
#define MAGNITUDE_TEMPERATURE 1
279+
#define MAGNITUDE_HUMIDITY 2
280+
#define MAGNITUDE_PRESSURE 3
281+
#define MAGNITUDE_CURRENT 4
282+
#define MAGNITUDE_VOLTAGE 5
283+
#define MAGNITUDE_POWER_ACTIVE 6
284+
#define MAGNITUDE_POWER_APPARENT 7
285+
#define MAGNITUDE_POWER_REACTIVE 8
286+
#define MAGNITUDE_POWER_FACTOR 9
287+
#define MAGNITUDE_ENERGY 10
288+
#define MAGNITUDE_ENERGY_DELTA 11
289+
#define MAGNITUDE_ANALOG 12
290+
#define MAGNITUDE_DIGITAL 13
291+
#define MAGNITUDE_EVENT 14
292+
#define MAGNITUDE_PM1dot0 15
293+
#define MAGNITUDE_PM2dot5 16
294+
#define MAGNITUDE_PM10 17
295+
#define MAGNITUDE_PARTICLES_0dot3 18
296+
#define MAGNITUDE_PARTICLES_0dot5 19
297+
#define MAGNITUDE_PARTICLES_1 20
298+
#define MAGNITUDE_PARTICLES_2dot5 21
299+
#define MAGNITUDE_PARTICLES_5 22
300+
#define MAGNITUDE_PARTICLES_10 23
301+
#define MAGNITUDE_CO2 24
302+
#define MAGNITUDE_LUX 25
303+
#define MAGNITUDE_UV 26
304+
#define MAGNITUDE_DISTANCE 27
305+
#define MAGNITUDE_HCHO 28
306+
#define MAGNITUDE_GEIGER_CPM 29
307+
#define MAGNITUDE_GEIGER_SIEVERT 30
308+
#define MAGNITUDE_COUNT 31
309+
310+
#define MAGNITUDE_MAX 32

code/espurna/sensor.ino

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

995995

996996
String magnitudeUnits(unsigned char type) {
997-
char buffer[8] = {0};
997+
char buffer[14] = {0};
998998
if (type < MAGNITUDE_MAX) {
999999
if ((type == MAGNITUDE_TEMPERATURE) && (_sensor_temperature_units == TMP_FAHRENHEIT)) {
10001000
strncpy_P(buffer, magnitude_fahrenheit, sizeof(buffer));

code/espurna/sensors/PMSX003Sensor.h

+24-3
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,31 @@
2626
#define PMS_TYPE_5003ST 3
2727

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

code/html/custom.js

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

0 commit comments

Comments
 (0)