mirror of
https://github.com/arendst/Tasmota.git
synced 2025-07-26 04:06:34 +00:00
Add interval to PMS5003 sensor
Add interval to PMS5003 sensor to extend lifetime (#8128)
This commit is contained in:
parent
0d2287dc94
commit
0c24651ed0
@ -66,6 +66,7 @@ The following binary downloads have been compiled with ESP8266/Arduino library c
|
|||||||
- Add Zigbee command ``ZbRestore`` to restore device configuration dumped with ``ZbStatus 2``
|
- Add Zigbee command ``ZbRestore`` to restore device configuration dumped with ``ZbStatus 2``
|
||||||
- Add Zigbee command ``ZbUnbind``
|
- Add Zigbee command ``ZbUnbind``
|
||||||
- Add Zigbee command ``ZbBindState`` and ``manuf``attribute
|
- Add Zigbee command ``ZbBindState`` and ``manuf``attribute
|
||||||
|
- Add Zigbee command ``ZbConfig`` and configuration in Settings
|
||||||
- Add commands ``CounterDebounceLow`` and ``CounterDebounceHigh`` to control debouncing (#8021)
|
- Add commands ``CounterDebounceLow`` and ``CounterDebounceHigh`` to control debouncing (#8021)
|
||||||
- Add commands ``NrfPage``, ``NrfIgnore``, ``NrfScan`` and ``NrfBeacon`` to NRF24 Bluetooth driver (#8075)
|
- Add commands ``NrfPage``, ``NrfIgnore``, ``NrfScan`` and ``NrfBeacon`` to NRF24 Bluetooth driver (#8075)
|
||||||
- Add command ``SetOption41 <x>`` to force sending gratuitous ARP every <x> seconds
|
- Add command ``SetOption41 <x>`` to force sending gratuitous ARP every <x> seconds
|
||||||
@ -86,3 +87,4 @@ The following binary downloads have been compiled with ESP8266/Arduino library c
|
|||||||
- Add console command history (#7483, #8015)
|
- Add console command history (#7483, #8015)
|
||||||
- Add quick wifi reconnect using saved AP parameters when ``SetOption56 0`` (#3189)
|
- Add quick wifi reconnect using saved AP parameters when ``SetOption56 0`` (#3189)
|
||||||
- Add more accuracy to GPS NTP server (#8088)
|
- Add more accuracy to GPS NTP server (#8088)
|
||||||
|
- Add interval to PMS5003 sensor to extend lifetime (#8128)
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
- Fix Zigbee crash with Occupancy sensor (#8089)
|
- Fix Zigbee crash with Occupancy sensor (#8089)
|
||||||
- Add support for longer template names
|
- Add support for longer template names
|
||||||
- Add Zigbee command ``ZbBindState`` and ``manuf``attribute
|
- Add Zigbee command ``ZbBindState`` and ``manuf``attribute
|
||||||
|
- Add Zigbee command ``ZbConfig`` and configuration in Settings
|
||||||
- Add commands ``CounterDebounceLow`` and ``CounterDebounceHigh`` to control debouncing (#8021)
|
- Add commands ``CounterDebounceLow`` and ``CounterDebounceHigh`` to control debouncing (#8021)
|
||||||
- Add commands ``NrfPage``, ``NrfIgnore``, ``NrfScan`` and ``NrfBeacon`` to NRF24 Bluetooth driver (#8075)
|
- Add commands ``NrfPage``, ``NrfIgnore``, ``NrfScan`` and ``NrfBeacon`` to NRF24 Bluetooth driver (#8075)
|
||||||
- Add command ``SetOption90 1`` to disable non-json MQTT messages (#8044)
|
- Add command ``SetOption90 1`` to disable non-json MQTT messages (#8044)
|
||||||
@ -25,7 +26,7 @@
|
|||||||
- Add support for an iAQ sensor (#8107)
|
- Add support for an iAQ sensor (#8107)
|
||||||
- Add support for Seven Segment display using HT16K33 (#8116)
|
- Add support for Seven Segment display using HT16K33 (#8116)
|
||||||
- Add support for AS3935 Lightning Sensor by device111 (#8130)
|
- Add support for AS3935 Lightning Sensor by device111 (#8130)
|
||||||
- Add Zigbee command ``ZbConfig`` and configuration in Settings
|
- Add interval to PMS5003 sensor to extend lifetime (#8128)
|
||||||
|
|
||||||
### 8.2.0.2 20200328
|
### 8.2.0.2 20200328
|
||||||
|
|
||||||
|
@ -505,9 +505,9 @@ struct PACKED SYSCFG {
|
|||||||
uint16_t zb_pan_id; // F30
|
uint16_t zb_pan_id; // F30
|
||||||
uint8_t zb_channel; // F32
|
uint8_t zb_channel; // F32
|
||||||
uint8_t zb_free_byte; // F33
|
uint8_t zb_free_byte; // F33
|
||||||
uint16_t pms_wake_interval;
|
uint16_t pms_wake_interval; // F34
|
||||||
|
|
||||||
uint8_t free_f18[130]; // F34
|
uint8_t free_f36[130]; // F36
|
||||||
|
|
||||||
uint16_t pulse_counter_debounce_low; // FB8
|
uint16_t pulse_counter_debounce_low; // FB8
|
||||||
uint16_t pulse_counter_debounce_high; // FBA
|
uint16_t pulse_counter_debounce_high; // FBA
|
||||||
|
@ -42,14 +42,13 @@
|
|||||||
|
|
||||||
TasmotaSerial *PmsSerial;
|
TasmotaSerial *PmsSerial;
|
||||||
|
|
||||||
uint8_t pms_type = 1;
|
struct PMS5003 {
|
||||||
uint8_t pms_valid = 0;
|
uint16_t time = 0;
|
||||||
uint16_t pms_time = 0;
|
uint8_t type = 1;
|
||||||
|
uint8_t valid = 0;
|
||||||
uint8_t wake_mode = 1;
|
uint8_t wake_mode = 1;
|
||||||
uint8_t pms_ready = 1;
|
uint8_t ready = 1;
|
||||||
|
} Pms;
|
||||||
const char ACTIVE_MODE[] = "Active Mode";
|
|
||||||
const char PASSIVE_MODE[] = "Passive Mode";
|
|
||||||
|
|
||||||
enum PmsCommands
|
enum PmsCommands
|
||||||
{
|
{
|
||||||
@ -155,7 +154,7 @@ bool PmsReadData(void)
|
|||||||
#else
|
#else
|
||||||
memcpy((void *)&pms_data, (void *)buffer_u16, 30);
|
memcpy((void *)&pms_data, (void *)buffer_u16, 30);
|
||||||
#endif // PMS_MODEL_PMS3003
|
#endif // PMS_MODEL_PMS3003
|
||||||
pms_valid = 10;
|
Pms.valid = 10;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -172,13 +171,12 @@ bool PmsReadData(void)
|
|||||||
|
|
||||||
bool PmsCommandSensor(void)
|
bool PmsCommandSensor(void)
|
||||||
{
|
{
|
||||||
if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload < 65536))
|
if ((pin[GPIO_PMS5003_TX] < 99) && (XdrvMailbox.payload >= 0) && (XdrvMailbox.payload < 65536)) {
|
||||||
{
|
|
||||||
if (XdrvMailbox.payload < MIN_INTERVAL_PERIOD) {
|
if (XdrvMailbox.payload < MIN_INTERVAL_PERIOD) {
|
||||||
// Set Active Mode if interval is less than 60 seconds
|
// Set Active Mode if interval is less than 60 seconds
|
||||||
Settings.pms_wake_interval = 0;
|
Settings.pms_wake_interval = 0;
|
||||||
wake_mode = 1;
|
Pms.wake_mode = 1;
|
||||||
pms_ready = 1;
|
Pms.ready = 1;
|
||||||
PmsSendCmd(CMD_MODE_ACTIVE);
|
PmsSendCmd(CMD_MODE_ACTIVE);
|
||||||
PmsSendCmd(CMD_WAKEUP);
|
PmsSendCmd(CMD_WAKEUP);
|
||||||
} else {
|
} else {
|
||||||
@ -186,17 +184,11 @@ bool PmsCommandSensor(void)
|
|||||||
Settings.pms_wake_interval = XdrvMailbox.payload;
|
Settings.pms_wake_interval = XdrvMailbox.payload;
|
||||||
PmsSendCmd(CMD_MODE_PASSIVE);
|
PmsSendCmd(CMD_MODE_PASSIVE);
|
||||||
PmsSendCmd(CMD_SLEEP);
|
PmsSendCmd(CMD_SLEEP);
|
||||||
wake_mode = 0;
|
Pms.wake_mode = 0;
|
||||||
pms_ready = 0;
|
Pms.ready = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pin[GPIO_PMS5003_TX] >= 99)
|
|
||||||
{
|
|
||||||
// setting interval not supported if TX pin not connected
|
|
||||||
Settings.pms_wake_interval = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
Response_P(S_JSON_SENSOR_INDEX_NVALUE, XSNS_18, Settings.pms_wake_interval);
|
Response_P(S_JSON_SENSOR_INDEX_NVALUE, XSNS_18, Settings.pms_wake_interval);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -206,46 +198,36 @@ bool PmsCommandSensor(void)
|
|||||||
|
|
||||||
void PmsSecond(void) // Every second
|
void PmsSecond(void) // Every second
|
||||||
{
|
{
|
||||||
if (Settings.pms_wake_interval >= MIN_INTERVAL_PERIOD)
|
if (Settings.pms_wake_interval >= MIN_INTERVAL_PERIOD) {
|
||||||
{
|
|
||||||
// Passive Mode
|
// Passive Mode
|
||||||
pms_time++;
|
Pms.time++;
|
||||||
if ((Settings.pms_wake_interval - pms_time <= WARMUP_PERIOD) && !wake_mode)
|
if ((Settings.pms_wake_interval - Pms.time <= WARMUP_PERIOD) && !Pms.wake_mode) {
|
||||||
{
|
|
||||||
// wakeup sensor WARMUP_PERIOD before read interval
|
// wakeup sensor WARMUP_PERIOD before read interval
|
||||||
wake_mode = 1;
|
Pms.wake_mode = 1;
|
||||||
PmsSendCmd(CMD_WAKEUP);
|
PmsSendCmd(CMD_WAKEUP);
|
||||||
}
|
}
|
||||||
if (pms_time >= Settings.pms_wake_interval)
|
if (Pms.time >= Settings.pms_wake_interval) {
|
||||||
{
|
|
||||||
// sensor is awake and warmed up, set up for reading
|
// sensor is awake and warmed up, set up for reading
|
||||||
PmsSendCmd(CMD_READ_DATA);
|
PmsSendCmd(CMD_READ_DATA);
|
||||||
pms_ready = 1;
|
Pms.ready = 1;
|
||||||
pms_time = 0;
|
Pms.time = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pms_ready)
|
if (Pms.ready) {
|
||||||
{
|
if (PmsReadData()) {
|
||||||
if (PmsReadData())
|
Pms.valid = 10;
|
||||||
{
|
if (Settings.pms_wake_interval >= MIN_INTERVAL_PERIOD) {
|
||||||
pms_valid = 10;
|
|
||||||
if (Settings.pms_wake_interval >= MIN_INTERVAL_PERIOD)
|
|
||||||
{
|
|
||||||
PmsSendCmd(CMD_SLEEP);
|
PmsSendCmd(CMD_SLEEP);
|
||||||
wake_mode = 0;
|
Pms.wake_mode = 0;
|
||||||
pms_ready = 0;
|
Pms.ready = 0;
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
if (Pms.valid) {
|
||||||
{
|
Pms.valid--;
|
||||||
if (pms_valid)
|
if (Settings.pms_wake_interval >= MIN_INTERVAL_PERIOD) {
|
||||||
{
|
|
||||||
pms_valid--;
|
|
||||||
if (Settings.pms_wake_interval >= MIN_INTERVAL_PERIOD)
|
|
||||||
{
|
|
||||||
PmsSendCmd(CMD_READ_DATA);
|
PmsSendCmd(CMD_READ_DATA);
|
||||||
pms_ready = 1;
|
Pms.ready = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -256,25 +238,18 @@ void PmsSecond(void) // Every second
|
|||||||
|
|
||||||
void PmsInit(void)
|
void PmsInit(void)
|
||||||
{
|
{
|
||||||
pms_type = 0;
|
Pms.type = 0;
|
||||||
if ((pin[GPIO_PMS5003_RX] < 99) && (pin[GPIO_PMS5003_TX] < 99))
|
if (pin[GPIO_PMS5003_RX] < 99) {
|
||||||
{
|
PmsSerial = new TasmotaSerial(pin[GPIO_PMS5003_RX], (pin[GPIO_PMS5003_TX] < 99) ? pin[GPIO_PMS5003_TX] : -1, 1);
|
||||||
PmsSerial = new TasmotaSerial(pin[GPIO_PMS5003_RX], pin[GPIO_PMS5003_TX], 1);
|
|
||||||
if (PmsSerial->begin(9600)) {
|
if (PmsSerial->begin(9600)) {
|
||||||
if (PmsSerial->hardwareSerial()) { ClaimSerial(); }
|
if (PmsSerial->hardwareSerial()) { ClaimSerial(); }
|
||||||
pms_type = 1;
|
|
||||||
|
if (99 == pin[GPIO_PMS5003_TX]) { // setting interval not supported if TX pin not connected
|
||||||
|
Settings.pms_wake_interval = 0;
|
||||||
|
Pms.ready = 1;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else if ((pin[GPIO_PMS5003_RX] < 99))
|
Pms.type = 1;
|
||||||
{
|
|
||||||
PmsSerial = new TasmotaSerial(pin[GPIO_PMS5003_RX], -1, 1);
|
|
||||||
if (PmsSerial->begin(9600))
|
|
||||||
{
|
|
||||||
if (PmsSerial->hardwareSerial())
|
|
||||||
{
|
|
||||||
ClaimSerial();
|
|
||||||
}
|
|
||||||
pms_type = 1;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -307,7 +282,7 @@ const char HTTP_PMS5003_SNS[] PROGMEM =
|
|||||||
|
|
||||||
void PmsShow(bool json)
|
void PmsShow(bool json)
|
||||||
{
|
{
|
||||||
if (pms_valid) {
|
if (Pms.valid) {
|
||||||
if (json) {
|
if (json) {
|
||||||
#ifdef PMS_MODEL_PMS3003
|
#ifdef PMS_MODEL_PMS3003
|
||||||
ResponseAppend_P(PSTR(",\"PMS3003\":{\"CF1\":%d,\"CF2.5\":%d,\"CF10\":%d,\"PM1\":%d,\"PM2.5\":%d,\"PM10\":%d}"),
|
ResponseAppend_P(PSTR(",\"PMS3003\":{\"CF1\":%d,\"CF2.5\":%d,\"CF10\":%d,\"PM1\":%d,\"PM2.5\":%d,\"PM10\":%d}"),
|
||||||
@ -352,7 +327,7 @@ bool Xsns18(uint8_t function)
|
|||||||
{
|
{
|
||||||
bool result = false;
|
bool result = false;
|
||||||
|
|
||||||
if (pms_type) {
|
if (Pms.type) {
|
||||||
switch (function) {
|
switch (function) {
|
||||||
case FUNC_INIT:
|
case FUNC_INIT:
|
||||||
PmsInit();
|
PmsInit();
|
||||||
@ -361,8 +336,7 @@ bool Xsns18(uint8_t function)
|
|||||||
PmsSecond();
|
PmsSecond();
|
||||||
break;
|
break;
|
||||||
case FUNC_COMMAND_SENSOR:
|
case FUNC_COMMAND_SENSOR:
|
||||||
if (XSNS_18 == XdrvMailbox.index)
|
if (XSNS_18 == XdrvMailbox.index) {
|
||||||
{
|
|
||||||
result = PmsCommandSensor();
|
result = PmsCommandSensor();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user