mirror of https://github.com/arendst/Tasmota.git
Merge pull request #2841 from JohannWeging/development
Add Nova SDS0X1 sensor idling to expand its lifespan
This commit is contained in:
commit
649ec49478
|
@ -475,7 +475,8 @@
|
|||
#define D_SENSOR_SPI_DC "SPI DC"
|
||||
#define D_SENSOR_BACKLIGHT "Подсветка"
|
||||
#define D_SENSOR_PMS5003 "PMS5003"
|
||||
#define D_SENSOR_SDS0X1 "SDS0X1"
|
||||
#define D_SENSOR_SDS0X1_RX "SDS0X1 Rx"
|
||||
#define D_SENSOR_SDS0X1_TX "SDS0X1 Tx"
|
||||
#define D_SENSOR_SBR_RX "SerBr Rx"
|
||||
#define D_SENSOR_SBR_TX "SerBr Tx"
|
||||
#define D_SENSOR_SR04_TRIG "SR04 Tri"
|
||||
|
|
|
@ -475,7 +475,8 @@
|
|||
#define D_SENSOR_SPI_DC "SPI DC"
|
||||
#define D_SENSOR_BACKLIGHT "BkLight"
|
||||
#define D_SENSOR_PMS5003 "PMS5003"
|
||||
#define D_SENSOR_SDS0X1 "SDS0X1"
|
||||
#define D_SENSOR_SDS0X1_RX "SDS0X1 Rx"
|
||||
#define D_SENSOR_SDS0X1_TX "SDS0X1 Tx"
|
||||
#define D_SENSOR_SBR_RX "SerBr Rx"
|
||||
#define D_SENSOR_SBR_TX "SerBr Tx"
|
||||
#define D_SENSOR_SR04_TRIG "SR04 Tri"
|
||||
|
|
|
@ -475,7 +475,8 @@
|
|||
#define D_SENSOR_SPI_DC "SPI DC"
|
||||
#define D_SENSOR_BACKLIGHT "BkLight"
|
||||
#define D_SENSOR_PMS5003 "PMS5003"
|
||||
#define D_SENSOR_SDS0X1 "SDS0X1"
|
||||
#define D_SENSOR_SDS0X1_RX "SDS0X1 Rx"
|
||||
#define D_SENSOR_SDS0X1_TX "SDS0X1 Tx"
|
||||
#define D_SENSOR_SBR_RX "SerBr Rx"
|
||||
#define D_SENSOR_SBR_TX "SerBr Tx"
|
||||
#define D_SENSOR_SR04_TRIG "SR04 Tri"
|
||||
|
|
|
@ -475,7 +475,8 @@
|
|||
#define D_SENSOR_SPI_DC "SPI DC"
|
||||
#define D_SENSOR_BACKLIGHT "BkLight"
|
||||
#define D_SENSOR_PMS5003 "PMS5003"
|
||||
#define D_SENSOR_SDS0X1 "SDS0X1"
|
||||
#define D_SENSOR_SDS0X1_RX "SDS0X1 Rx"
|
||||
#define D_SENSOR_SDS0X1_TX "SDS0X1 Tx"
|
||||
#define D_SENSOR_SBR_RX "SerBr Rx"
|
||||
#define D_SENSOR_SBR_TX "SerBr Tx"
|
||||
#define D_SENSOR_SR04_TRIG "SR04 Tri"
|
||||
|
|
|
@ -475,7 +475,8 @@
|
|||
#define D_SENSOR_SPI_DC "SPI DC"
|
||||
#define D_SENSOR_BACKLIGHT "BkLight"
|
||||
#define D_SENSOR_PMS5003 "PMS5003"
|
||||
#define D_SENSOR_SDS0X1 "SDS0X1"
|
||||
#define D_SENSOR_SDS0X1_RX "SDS0X1 Rx"
|
||||
#define D_SENSOR_SDS0X1_TX "SDS0X1 Tx"
|
||||
#define D_SENSOR_SBR_RX "SerBr Rx"
|
||||
#define D_SENSOR_SBR_TX "SerBr Tx"
|
||||
#define D_SENSOR_SR04_TRIG "SR04 Tri"
|
||||
|
|
|
@ -475,7 +475,8 @@
|
|||
#define D_SENSOR_SPI_DC "SPI DC"
|
||||
#define D_SENSOR_BACKLIGHT "BkLight"
|
||||
#define D_SENSOR_PMS5003 "PMS5003"
|
||||
#define D_SENSOR_SDS0X1 "SDS0X1"
|
||||
#define D_SENSOR_SDS0X1_RX "SDS0X1 Rx"
|
||||
#define D_SENSOR_SDS0X1_TX "SDS0X1 Tx"
|
||||
#define D_SENSOR_SBR_RX "SerBr Rx"
|
||||
#define D_SENSOR_SBR_TX "SerBr Tx"
|
||||
#define D_SENSOR_SR04_TRIG "SR04 Tri"
|
||||
|
|
|
@ -475,7 +475,8 @@
|
|||
#define D_SENSOR_SPI_DC "SPI DC"
|
||||
#define D_SENSOR_BACKLIGHT "RétroÉcl"
|
||||
#define D_SENSOR_PMS5003 "PMS5003"
|
||||
#define D_SENSOR_SDS0X1 "SDS0X1"
|
||||
#define D_SENSOR_SDS0X1_RX "SDS0X1 Rx"
|
||||
#define D_SENSOR_SDS0X1_TX "SDS0X1 Tx"
|
||||
#define D_SENSOR_SBR_RX "SerBr Rx"
|
||||
#define D_SENSOR_SBR_TX "SerBr Tx"
|
||||
#define D_SENSOR_SR04_TRIG "SR04 Tri"
|
||||
|
|
|
@ -475,7 +475,8 @@
|
|||
#define D_SENSOR_SPI_DC "SPI DC"
|
||||
#define D_SENSOR_BACKLIGHT "Háttérvil"
|
||||
#define D_SENSOR_PMS5003 "PMS5003"
|
||||
#define D_SENSOR_SDS0X1 "SDS0X1"
|
||||
#define D_SENSOR_SDS0X1_RX "SDS0X1 Rx"
|
||||
#define D_SENSOR_SDS0X1_TX "SDS0X1 Tx"
|
||||
#define D_SENSOR_SBR_RX "SerBr Rx"
|
||||
#define D_SENSOR_SBR_TX "SerBr Tx"
|
||||
#define D_SENSOR_SR04_TRIG "SR04 Tri"
|
||||
|
|
|
@ -475,7 +475,8 @@
|
|||
#define D_SENSOR_SPI_DC "SPI DC"
|
||||
#define D_SENSOR_BACKLIGHT "BkLight"
|
||||
#define D_SENSOR_PMS5003 "PMS5003"
|
||||
#define D_SENSOR_SDS0X1 "SDS0X1"
|
||||
#define D_SENSOR_SDS0X1_RX "SDS0X1 Rx"
|
||||
#define D_SENSOR_SDS0X1_TX "SDS0X1 Tx"
|
||||
#define D_SENSOR_SBR_RX "SerBr Rx"
|
||||
#define D_SENSOR_SBR_TX "SerBr Tx"
|
||||
#define D_SENSOR_SR04_TRIG "SR04 Tri"
|
||||
|
|
|
@ -475,7 +475,8 @@
|
|||
#define D_SENSOR_SPI_DC "SPI DC"
|
||||
#define D_SENSOR_BACKLIGHT "BkLight"
|
||||
#define D_SENSOR_PMS5003 "PMS5003"
|
||||
#define D_SENSOR_SDS0X1 "SDS0X1"
|
||||
#define D_SENSOR_SDS0X1_RX "SDS0X1 Rx"
|
||||
#define D_SENSOR_SDS0X1_TX "SDS0X1 Tx"
|
||||
#define D_SENSOR_SBR_RX "SerBr Rx"
|
||||
#define D_SENSOR_SBR_TX "SerBr Tx"
|
||||
#define D_SENSOR_SR04_TRIG "SR04 Tri"
|
||||
|
|
|
@ -475,7 +475,8 @@
|
|||
#define D_SENSOR_SPI_DC "SPI DC"
|
||||
#define D_SENSOR_BACKLIGHT "BkLight"
|
||||
#define D_SENSOR_PMS5003 "PMS5003"
|
||||
#define D_SENSOR_SDS0X1 "SDS0X1"
|
||||
#define D_SENSOR_SDS0X1_RX "SDS0X1 Rx"
|
||||
#define D_SENSOR_SDS0X1_TX "SDS0X1 Tx"
|
||||
#define D_SENSOR_SBR_RX "SerBr Rx"
|
||||
#define D_SENSOR_SBR_TX "SerBr Tx"
|
||||
#define D_SENSOR_SR04_TRIG "SR04 Tri"
|
||||
|
|
|
@ -475,7 +475,8 @@
|
|||
#define D_SENSOR_SPI_DC "SPI DC"
|
||||
#define D_SENSOR_BACKLIGHT "Luz de fundo"
|
||||
#define D_SENSOR_PMS5003 "PMS5003"
|
||||
#define D_SENSOR_SDS0X1 "SDS0X1"
|
||||
#define D_SENSOR_SDS0X1_RX "SDS0X1 Rx"
|
||||
#define D_SENSOR_SDS0X1_TX "SDS0X1 Tx"
|
||||
#define D_SENSOR_SBR_RX "SerBr Rx"
|
||||
#define D_SENSOR_SBR_TX "SerBr Tx"
|
||||
#define D_SENSOR_SR04_TRIG "SR04 Tri"
|
||||
|
|
|
@ -475,7 +475,8 @@
|
|||
#define D_SENSOR_SPI_DC "SPI DC"
|
||||
#define D_SENSOR_BACKLIGHT "Luz negra"
|
||||
#define D_SENSOR_PMS5003 "PMS5003"
|
||||
#define D_SENSOR_SDS0X1 "SDS0X1"
|
||||
#define D_SENSOR_SDS0X1_RX "SDS0X1 Rx"
|
||||
#define D_SENSOR_SDS0X1_TX "SDS0X1 Tx"
|
||||
#define D_SENSOR_SBR_RX "SerBr Rx"
|
||||
#define D_SENSOR_SBR_TX "SerBr Tx"
|
||||
#define D_SENSOR_SR04_TRIG "SR04 Tri"
|
||||
|
|
|
@ -475,7 +475,8 @@
|
|||
#define D_SENSOR_SPI_DC "SPI DC"
|
||||
#define D_SENSOR_BACKLIGHT "BkLight"
|
||||
#define D_SENSOR_PMS5003 "PMS5003"
|
||||
#define D_SENSOR_SDS0X1 "SDS0X1"
|
||||
#define D_SENSOR_SDS0X1_RX "SDS0X1 Rx"
|
||||
#define D_SENSOR_SDS0X1_TX "SDS0X1 Tx"
|
||||
#define D_SENSOR_SBR_RX "SerBr Rx"
|
||||
#define D_SENSOR_SBR_TX "SerBr Tx"
|
||||
#define D_SENSOR_SR04_TRIG "SR04 Tri"
|
||||
|
|
|
@ -475,7 +475,8 @@
|
|||
#define D_SENSOR_SPI_DC "SPI DC"
|
||||
#define D_SENSOR_BACKLIGHT "BkLight"
|
||||
#define D_SENSOR_PMS5003 "PMS5003"
|
||||
#define D_SENSOR_SDS0X1 "SDS0X1"
|
||||
#define D_SENSOR_SDS0X1_RX "SDS0X1 Rx"
|
||||
#define D_SENSOR_SDS0X1_TX "SDS0X1 Tx"
|
||||
#define D_SENSOR_SBR_RX "SerBr Rx"
|
||||
#define D_SENSOR_SBR_TX "SerBr Tx"
|
||||
#define D_SENSOR_SR04_TRIG "SR04 Tri"
|
||||
|
|
|
@ -475,7 +475,8 @@
|
|||
#define D_SENSOR_SPI_DC "SPI DC"
|
||||
#define D_SENSOR_BACKLIGHT "BkLight"
|
||||
#define D_SENSOR_PMS5003 "PMS5003"
|
||||
#define D_SENSOR_SDS0X1 "SDS0X1"
|
||||
#define D_SENSOR_SDS0X1_RX "SDS0X1 Rx"
|
||||
#define D_SENSOR_SDS0X1_TX "SDS0X1 Tx"
|
||||
#define D_SENSOR_SBR_RX "SerBr Rx"
|
||||
#define D_SENSOR_SBR_TX "SerBr Tx"
|
||||
#define D_SENSOR_SR04_TRIG "SR04 Tri"
|
||||
|
|
|
@ -94,7 +94,8 @@ enum UserSelectablePins {
|
|||
GPIO_SPI_DC, // SPI Data Direction
|
||||
GPIO_BACKLIGHT, // Display backlight control
|
||||
GPIO_PMS5003, // Plantower PMS5003 Serial interface
|
||||
GPIO_SDS0X1, // Nova Fitness SDS011 Serial interface
|
||||
GPIO_SDS0X1_TX, // Nova Fitness SDS011 Serial interface
|
||||
GPIO_SDS0X1_RX, // Nova Fitness SDS011 Serial interface
|
||||
GPIO_SBR_TX, // Serial Bridge Serial interface
|
||||
GPIO_SBR_RX, // Serial Bridge Serial interface
|
||||
GPIO_SR04_TRIG, // SR04 Trigger pin
|
||||
|
@ -166,7 +167,8 @@ const char kSensorNames[] PROGMEM =
|
|||
D_SENSOR_PZEM_TX "|" D_SENSOR_PZEM_RX "|"
|
||||
D_SENSOR_SAIR_TX "|" D_SENSOR_SAIR_RX "|"
|
||||
D_SENSOR_SPI_CS "|" D_SENSOR_SPI_DC "|" D_SENSOR_BACKLIGHT "|"
|
||||
D_SENSOR_PMS5003 "|" D_SENSOR_SDS0X1 "|"
|
||||
D_SENSOR_PMS5003 "|"
|
||||
D_SENSOR_SDS0X1_TX "|" D_SENSOR_SDS0X1_RX "|"
|
||||
D_SENSOR_SBR_TX "|" D_SENSOR_SBR_RX "|"
|
||||
D_SENSOR_SR04_TRIG "|" D_SENSOR_SR04_ECHO "|"
|
||||
D_SENSOR_SDM120_TX "|" D_SENSOR_SDM120_RX "|"
|
||||
|
|
|
@ -628,7 +628,8 @@ boolean GetUsedInModule(byte val, uint8_t *arr)
|
|||
if (GPIO_PMS5003 == val) { return true; }
|
||||
#endif
|
||||
#ifndef USE_NOVA_SDS
|
||||
if (GPIO_SDS0X1 == val) { return true; }
|
||||
if (GPIO_SDS0X1_TX == val) { return true; }
|
||||
if (GPIO_SDS0X1_RX == val) { return true; }
|
||||
#endif
|
||||
#ifndef USE_SERIAL_BRIDGE
|
||||
if (GPIO_SBR_TX == val) { return true; }
|
||||
|
|
|
@ -31,13 +31,18 @@ TasmotaSerial *NovaSdsSerial;
|
|||
|
||||
uint8_t novasds_type = 1;
|
||||
uint8_t novasds_valid = 0;
|
||||
uint8_t novasds_running = 1;
|
||||
uint8_t novasds_read_tick = 30;
|
||||
uint8_t novasds_wakup_tick = 179;
|
||||
uint8_t novasds_ticker = 0;
|
||||
|
||||
struct sds011data {
|
||||
uint16_t pm100;
|
||||
uint16_t pm25;
|
||||
} novasds_data;
|
||||
|
||||
bool NovaSdsReadData()
|
||||
|
||||
bool NovaSdsReadData(bool publish)
|
||||
{
|
||||
if (! NovaSdsSerial->available()) return false;
|
||||
|
||||
|
@ -51,7 +56,9 @@ bool NovaSdsReadData()
|
|||
NovaSdsSerial->flush();
|
||||
|
||||
AddLogSerial(LOG_LEVEL_DEBUG_MORE, d, 8);
|
||||
|
||||
if (!publish){
|
||||
return false;
|
||||
}
|
||||
if (d[7] == ((d[1] + d[2] + d[3] + d[4] + d[5] + d[6]) & 0xFF)) {
|
||||
novasds_data.pm25 = (d[1] + 256 * d[2]);
|
||||
novasds_data.pm100 = (d[3] + 256 * d[4]);
|
||||
|
@ -59,9 +66,6 @@ bool NovaSdsReadData()
|
|||
AddLog_P(LOG_LEVEL_DEBUG, PSTR("SDS: " D_CHECKSUM_FAILURE));
|
||||
return false;
|
||||
}
|
||||
|
||||
novasds_valid = 10;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -69,12 +73,35 @@ bool NovaSdsReadData()
|
|||
|
||||
void NovaSdsSecond() // Every second
|
||||
{
|
||||
if (NovaSdsReadData()) {
|
||||
novasds_valid = 10;
|
||||
} else {
|
||||
if (novasds_valid) {
|
||||
novasds_valid--;
|
||||
if (novasds_ticker < novasds_read_tick) {
|
||||
// wake up the sensor and wait read ticks to stabalize the sensor
|
||||
if (!novasds_running) {
|
||||
NovaSdsStart();
|
||||
novasds_running = 1;
|
||||
}
|
||||
|
||||
// drain the serial without publishing data
|
||||
NovaSdsReadData(false);
|
||||
novasds_ticker++;
|
||||
|
||||
} else if (novasds_ticker == novasds_read_tick) {
|
||||
|
||||
// try to take a single stable reading and sleep the sensor
|
||||
if (NovaSdsReadData(true)) {
|
||||
novasds_valid = 1;
|
||||
NovaSdsStop();
|
||||
novasds_running = 0;
|
||||
novasds_ticker++;
|
||||
} else {
|
||||
novasds_valid = 0;
|
||||
}
|
||||
|
||||
} else if (novasds_ticker >= novasds_wakup_tick) {
|
||||
// reset the counter
|
||||
novasds_ticker = 0;
|
||||
} else {
|
||||
// sensor is sleeping keep waiting
|
||||
novasds_ticker++;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -83,12 +110,36 @@ void NovaSdsSecond() // Every second
|
|||
void NovaSdsInit()
|
||||
{
|
||||
novasds_type = 0;
|
||||
if (pin[GPIO_SDS0X1] < 99) {
|
||||
NovaSdsSerial = new TasmotaSerial(pin[GPIO_SDS0X1], -1, 1);
|
||||
if (pin[GPIO_SDS0X1_RX] < 99 && pin[GPIO_SDS0X1_TX] < 99) {
|
||||
NovaSdsSerial = new TasmotaSerial(pin[GPIO_SDS0X1_RX], pin[GPIO_SDS0X1_TX], 1);
|
||||
|
||||
if (NovaSdsSerial->begin(9600)) {
|
||||
if (NovaSdsSerial->hardwareSerial()) { ClaimSerial(); }
|
||||
if (NovaSdsSerial->hardwareSerial()) {
|
||||
ClaimSerial();
|
||||
}
|
||||
novasds_type = 1;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void NovaSdsStart()
|
||||
{
|
||||
AddLog_P(LOG_LEVEL_DEBUG, "SDS: start");
|
||||
const uint8_t novasds_start_cmd[] = {0xAA, 0xB4, 0x06, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x06, 0xAB};
|
||||
NovaSdsSerial->write(novasds_start_cmd, sizeof(novasds_start_cmd));
|
||||
NovaSdsSerial->flush();
|
||||
}
|
||||
|
||||
void NovaSdsStop()
|
||||
{
|
||||
AddLog_P(LOG_LEVEL_DEBUG, "SDS: stop");
|
||||
const uint8_t novasds_stop_cmd[] = {0xAA, 0xB4, 0x06, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x05, 0xAB};
|
||||
NovaSdsSerial->write(novasds_stop_cmd, sizeof(novasds_stop_cmd));
|
||||
NovaSdsSerial->flush();
|
||||
// drain any old data
|
||||
while (NovaSdsSerial->available()) {
|
||||
NovaSdsSerial->read();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -154,4 +205,4 @@ boolean Xsns20(byte function)
|
|||
return result;
|
||||
}
|
||||
|
||||
#endif // USE_NOVA_SDS
|
||||
#endif // USE_NOVA_SDS
|
||||
|
|
Loading…
Reference in New Issue