Merge pull request #6660 from vascojdb/pms3003

Added support for PMS3003
This commit is contained in:
Theo Arends 2019-10-16 13:04:55 +02:00 committed by GitHub
commit 51bf52d94d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 69 additions and 6 deletions

View File

@ -10,6 +10,7 @@
* Fix handling of ligth channels when pwm_multichannel (Option68) is enabled
* Add WebUI for multiple, independent PWM channels
* Remove default DS18B20 driver and only support define DS18x20 (#6647)
* Add support for PMS3003 dust particle sensor
*
* 6.6.0.17 20191009
* Add command SetOption34 0..255 to set backlog delay. Default value is 200 (mSeconds) (#6562)

View File

@ -427,6 +427,7 @@
#define CO2_LOW 800 // Below this CO2 value show green light (needs PWM or WS2812 RG(B) led and enable with SetOption18 1)
#define CO2_HIGH 1200 // Above this CO2 value show red light (needs PWM or WS2812 RG(B) led and enable with SetOption18 1)
#define USE_PMS5003 // Add support for PMS5003 and PMS7003 particle concentration sensor (+1k3 code)
//#define PMS_MODEL_PMS3003 // Enable support of PMS3003 instead of PMS5003/PMS7003 (needs the USE_PMS5003 above)
#define USE_NOVA_SDS // Add support for SDS011 and SDS021 particle concentration sensor (+0k7 code)
#define WORKING_PERIOD 5 // Working period of the SDS Sensor, Takes a reading every X Minutes
#define USE_SERIAL_BRIDGE // Add support for software Serial Bridge (+0k8 code)

View File

@ -147,6 +147,7 @@ char* ToHex_P(const unsigned char * in, size_t insz, char * out, size_t outsz, c
#define CO2_HIGH 1200 // Above this CO2 value show red light (needs PWM or WS2812 RG(B) led and enable with SetOption18 1)
#endif
#define USE_PMS5003 // Add support for PMS5003 and PMS7003 particle concentration sensor (+1k3 code)
//#define PMS_MODEL_PMS3003 // Enable support of PMS3003 instead of PMS5003/PMS7003 (needs the USE_PMS5003 above)
#define USE_NOVA_SDS // Add support for SDS011 and SDS021 particle concentration sensor (+0k7 code)
#define USE_SERIAL_BRIDGE // Add support for software Serial Bridge (+0k8 code)
//#define USE_SDM120 // Add support for Eastron SDM120-Modbus energy meter (+1k7 code)

View File

@ -1,5 +1,5 @@
/*
xsns_18_pms5003.ino - PMS5003-7003 particle concentration sensor support for Sonoff-Tasmota
xsns_18_pms5003.ino - PMS3003, PMS5003, PMS7003 particle concentration sensor support for Sonoff-Tasmota
Copyright (C) 2019 Theo Arends
@ -19,10 +19,13 @@
#ifdef USE_PMS5003
/*********************************************************************************************\
* PlanTower PMS5003 and PMS7003 particle concentration sensor
* For background information see http://aqicn.org/sensor/pms5003-7003/
* PlanTower PMS3003, PMS5003, PMS7003 particle concentration sensor
* For background information see http://aqicn.org/sensor/pms5003-7003/ or
* http://aqicn.org/sensor/pms3003/
*
* Hardware Serial will be selected if GPIO3 = [PMS5003]
* You can either support PMS3003 or PMS5003-7003 at one time. To enable the PMS3003 support
* you must enable the define PMS_MODEL_PMS3003 on your configuration file.
\*********************************************************************************************/
#define XSNS_18 18
@ -34,12 +37,16 @@ TasmotaSerial *PmsSerial;
uint8_t pms_type = 1;
uint8_t pms_valid = 0;
struct pms5003data {
struct pmsX003data {
uint16_t framelen;
uint16_t pm10_standard, pm25_standard, pm100_standard;
uint16_t pm10_env, pm25_env, pm100_env;
#ifdef PMS_MODEL_PMS3003
uint16_t reserved1, reserved2, reserved3;
#else
uint16_t particles_03um, particles_05um, particles_10um, particles_25um, particles_50um, particles_100um;
uint16_t unused;
#endif // PMS_MODEL_PMS3003
uint16_t checksum;
} pms_data;
@ -53,33 +60,63 @@ bool PmsReadData(void)
while ((PmsSerial->peek() != 0x42) && PmsSerial->available()) {
PmsSerial->read();
}
#ifdef PMS_MODEL_PMS3003
if (PmsSerial->available() < 22) {
#else
if (PmsSerial->available() < 32) {
#endif // PMS_MODEL_PMS3003
return false;
}
#ifdef PMS_MODEL_PMS3003
uint8_t buffer[22];
PmsSerial->readBytes(buffer, 22);
#else
uint8_t buffer[32];
uint16_t sum = 0;
PmsSerial->readBytes(buffer, 32);
#endif // PMS_MODEL_PMS3003
uint16_t sum = 0;
PmsSerial->flush(); // Make room for another burst
#ifdef PMS_MODEL_PMS3003
AddLogBuffer(LOG_LEVEL_DEBUG_MORE, buffer, 22);
#else
AddLogBuffer(LOG_LEVEL_DEBUG_MORE, buffer, 32);
#endif // PMS_MODEL_PMS3003
// get checksum ready
#ifdef PMS_MODEL_PMS3003
for (uint32_t i = 0; i < 20; i++) {
#else
for (uint32_t i = 0; i < 30; i++) {
#endif // PMS_MODEL_PMS3003
sum += buffer[i];
}
// The data comes in endian'd, this solves it so it works on all platforms
#ifdef PMS_MODEL_PMS3003
uint16_t buffer_u16[10];
for (uint32_t i = 0; i < 10; i++) {
#else
uint16_t buffer_u16[15];
for (uint32_t i = 0; i < 15; i++) {
#endif // PMS_MODEL_PMS3003
buffer_u16[i] = buffer[2 + i*2 + 1];
buffer_u16[i] += (buffer[2 + i*2] << 8);
}
#ifdef PMS_MODEL_PMS3003
if (sum != buffer_u16[9]) {
#else
if (sum != buffer_u16[14]) {
#endif // PMS_MODEL_PMS3003
AddLog_P(LOG_LEVEL_DEBUG, PSTR("PMS: " D_CHECKSUM_FAILURE));
return false;
}
#ifdef PMS_MODEL_PMS3003
memcpy((void *)&pms_data, (void *)buffer_u16, 20);
#else
memcpy((void *)&pms_data, (void *)buffer_u16, 30);
#endif // PMS_MODEL_PMS3003
pms_valid = 10;
return true;
@ -113,6 +150,15 @@ void PmsInit(void)
}
#ifdef USE_WEBSERVER
#ifdef PMS_MODEL_PMS3003
const char HTTP_PMS3003_SNS[] PROGMEM =
// "{s}PMS3003 " D_STANDARD_CONCENTRATION " 1 " D_UNIT_MICROMETER "{m}%d " D_UNIT_MICROGRAM_PER_CUBIC_METER "{e}"
// "{s}PMS3003 " D_STANDARD_CONCENTRATION " 2.5 " D_UNIT_MICROMETER "{m}%d " D_UNIT_MICROGRAM_PER_CUBIC_METER "{e}"
// "{s}PMS3003 " D_STANDARD_CONCENTRATION " 10 " D_UNIT_MICROMETER "{m}%d " D_UNIT_MICROGRAM_PER_CUBIC_METER "{e}"
"{s}PMS3003 " D_ENVIRONMENTAL_CONCENTRATION " 1 " D_UNIT_MICROMETER "{m}%d " D_UNIT_MICROGRAM_PER_CUBIC_METER "{e}"
"{s}PMS3003 " D_ENVIRONMENTAL_CONCENTRATION " 2.5 " D_UNIT_MICROMETER "{m}%d " D_UNIT_MICROGRAM_PER_CUBIC_METER "{e}"
"{s}PMS3003 " D_ENVIRONMENTAL_CONCENTRATION " 10 " D_UNIT_MICROMETER "{m}%d " D_UNIT_MICROGRAM_PER_CUBIC_METER "{e}";
#else
const char HTTP_PMS5003_SNS[] PROGMEM =
// "{s}PMS5003 " D_STANDARD_CONCENTRATION " 1 " D_UNIT_MICROMETER "{m}%d " D_UNIT_MICROGRAM_PER_CUBIC_METER "{e}"
// "{s}PMS5003 " D_STANDARD_CONCENTRATION " 2.5 " D_UNIT_MICROMETER "{m}%d " D_UNIT_MICROGRAM_PER_CUBIC_METER "{e}"
@ -126,16 +172,23 @@ const char HTTP_PMS5003_SNS[] PROGMEM =
"{s}PMS5003 " D_PARTICALS_BEYOND " 2.5 " D_UNIT_MICROMETER "{m}%d " D_UNIT_PARTS_PER_DECILITER "{e}"
"{s}PMS5003 " D_PARTICALS_BEYOND " 5 " D_UNIT_MICROMETER "{m}%d " D_UNIT_PARTS_PER_DECILITER "{e}"
"{s}PMS5003 " D_PARTICALS_BEYOND " 10 " D_UNIT_MICROMETER "{m}%d " D_UNIT_PARTS_PER_DECILITER "{e}"; // {s} = <tr><th>, {m} = </th><td>, {e} = </td></tr>
#endif // PMS_MODEL_PMS3003
#endif // USE_WEBSERVER
void PmsShow(bool json)
{
if (pms_valid) {
if (json) {
#ifdef PMS_MODEL_PMS3003
ResponseAppend_P(PSTR(",\"PMS3003\":{\"CF1\":%d,\"CF2.5\":%d,\"CF10\":%d,\"PM1\":%d,\"PM2.5\":%d,\"PM10\":%d}"),
pms_data.pm10_standard, pms_data.pm25_standard, pms_data.pm100_standard,
pms_data.pm10_env, pms_data.pm25_env, pms_data.pm100_env);
#else
ResponseAppend_P(PSTR(",\"PMS5003\":{\"CF1\":%d,\"CF2.5\":%d,\"CF10\":%d,\"PM1\":%d,\"PM2.5\":%d,\"PM10\":%d,\"PB0.3\":%d,\"PB0.5\":%d,\"PB1\":%d,\"PB2.5\":%d,\"PB5\":%d,\"PB10\":%d}"),
pms_data.pm10_standard, pms_data.pm25_standard, pms_data.pm100_standard,
pms_data.pm10_env, pms_data.pm25_env, pms_data.pm100_env,
pms_data.particles_03um, pms_data.particles_05um, pms_data.particles_10um, pms_data.particles_25um, pms_data.particles_50um, pms_data.particles_100um);
#endif // PMS_MODEL_PMS3003
#ifdef USE_DOMOTICZ
if (0 == tele_period) {
DomoticzSensor(DZ_COUNT, pms_data.pm10_env); // PM1
@ -145,10 +198,17 @@ void PmsShow(bool json)
#endif // USE_DOMOTICZ
#ifdef USE_WEBSERVER
} else {
WSContentSend_PD(HTTP_PMS5003_SNS,
#ifdef PMS_MODEL_PMS3003
WSContentSend_PD(HTTP_PMS3003_SNS,
// pms_data.pm10_standard, pms_data.pm25_standard, pms_data.pm100_standard,
pms_data.pm10_env, pms_data.pm25_env, pms_data.pm100_env);
#else
WSContentSend_PD(HTTP_PMS5003_SNS,
// pms_data.pm10_standard, pms_data.pm25_standard, pms_data.pm100_standard,
pms_data.pm10_env, pms_data.pm25_env, pms_data.pm100_env,
pms_data.particles_03um, pms_data.particles_05um, pms_data.particles_10um, pms_data.particles_25um, pms_data.particles_50um, pms_data.particles_100um);
#endif // PMS_MODEL_PMS3003
#endif // USE_WEBSERVER
}
}