Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Nova SDS0X1 sensor idling to expand its lifespan #2841

Merged
merged 8 commits into from
Sep 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion sonoff/language/bg-BG.h
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,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"
Expand Down
3 changes: 2 additions & 1 deletion sonoff/language/cs-CZ.h
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,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"
Expand Down
3 changes: 2 additions & 1 deletion sonoff/language/de-DE.h
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,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"
Expand Down
3 changes: 2 additions & 1 deletion sonoff/language/el-GR.h
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,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"
Expand Down
3 changes: 2 additions & 1 deletion sonoff/language/en-GB.h
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,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"
Expand Down
3 changes: 2 additions & 1 deletion sonoff/language/es-AR.h
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,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"
Expand Down
3 changes: 2 additions & 1 deletion sonoff/language/fr-FR.h
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,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"
Expand Down
3 changes: 2 additions & 1 deletion sonoff/language/hu-HU.h
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,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"
Expand Down
3 changes: 2 additions & 1 deletion sonoff/language/it-IT.h
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,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"
Expand Down
3 changes: 2 additions & 1 deletion sonoff/language/nl-NL.h
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,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"
Expand Down
3 changes: 2 additions & 1 deletion sonoff/language/pl-PL.h
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,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"
Expand Down
3 changes: 2 additions & 1 deletion sonoff/language/pt-BR.h
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,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"
Expand Down
3 changes: 2 additions & 1 deletion sonoff/language/pt-PT.h
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,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"
Expand Down
3 changes: 2 additions & 1 deletion sonoff/language/ru-RU.h
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,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"
Expand Down
3 changes: 2 additions & 1 deletion sonoff/language/zh-CN.h
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,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"
Expand Down
3 changes: 2 additions & 1 deletion sonoff/language/zh-TW.h
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,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"
Expand Down
8 changes: 5 additions & 3 deletions sonoff/sonoff_template.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,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
Expand Down Expand Up @@ -138,7 +139,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 "|"
Expand Down Expand Up @@ -912,4 +914,4 @@ const mytmplt kModules[MAXMODULE] PROGMEM = {

*/

#endif // _SONOFF_TEMPLATE_H_
#endif // _SONOFF_TEMPLATE_H_
3 changes: 2 additions & 1 deletion sonoff/support.ino
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,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; }
Expand Down
79 changes: 65 additions & 14 deletions sonoff/xsns_20_novasds.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -51,30 +56,52 @@ 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]);
} else {
AddLog_P(LOG_LEVEL_DEBUG, PSTR("SDS: " D_CHECKSUM_FAILURE));
return false;
}

novasds_valid = 10;

return true;
}

/*********************************************************************************************/

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++;
}
}

Expand All @@ -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();
}
}

Expand Down Expand Up @@ -154,4 +205,4 @@ boolean Xsns20(byte function)
return result;
}

#endif // USE_NOVA_SDS
#endif // USE_NOVA_SDS