diff --git a/include/sds011read.h b/include/sds011read.h index f49c34f0..db651ebf 100644 --- a/include/sds011read.h +++ b/include/sds011read.h @@ -1,11 +1,13 @@ #ifndef _SDS011READ_H #define _SDS011READ_H -#include +#include #include "globals.h" #define SDCARD_FILE_HEADER_SDS011 ", PM10,PM25" +extern bool isSDS011Active; + bool sds011_init(); void sds011_loop(); void sds011_sleep(void); diff --git a/platformio_orig.ini b/platformio_orig.ini index 0fea3a83..632ef7e8 100644 --- a/platformio_orig.ini +++ b/platformio_orig.ini @@ -77,7 +77,7 @@ lib_deps_sensors = adafruit/Adafruit BME280 Library @ ^2.2.1 adafruit/Adafruit BMP085 Library @ ^1.2.0 boschsensortec/BSEC Software Library @ 1.6.1480 - https://github.com/ricki-z/SDS011.git + https://github.com/cyberman54/sds-dust-sensors-arduino-library.git lib_deps_basic = https://github.com/dbSuS/libpax.git @ ^1.0.0 https://github.com/SukkoPera/Arduino-Rokkit-Hash.git diff --git a/src/cyclic.cpp b/src/cyclic.cpp index 33a0022d..67d21262 100644 --- a/src/cyclic.cpp +++ b/src/cyclic.cpp @@ -9,10 +9,6 @@ static const char TAG[] = __FILE__; Ticker cyclicTimer; -#if (HAS_SDS011) -extern boolean isSDS011Active; -#endif - void setCyclicIRQ() { xTaskNotify(irqHandlerTask, CYCLIC_IRQ, eSetBits); } // do all housekeeping diff --git a/src/sds011read.cpp b/src/sds011read.cpp index a693f651..76719d42 100644 --- a/src/sds011read.cpp +++ b/src/sds011read.cpp @@ -10,35 +10,41 @@ static const char TAG[] = __FILE__; #if (HAS_IF482) #error cannot use IF482 together with SDS011 (both use UART#2) #endif -// UART(2) is unused in this project -static HardwareSerial sdsSerial(2); // so we use it here -static SDS011 sdsSensor; // fine dust sensor + +// sds011 connected to UART(2) +static SdsDustSensor sdsSensor(Serial2); // the results of the sensor: static float pm10, pm25; -boolean isSDS011Active; +bool isSDS011Active = false; // init bool sds011_init() { pm25 = pm10 = 0.0; - sdsSensor.begin(&sdsSerial, SDS_RX, SDS_TX); + sdsSensor.begin(); + + String version = sdsSensor.queryFirmwareVersion().toString(); + ESP_LOGI(TAG, "SDS011 firmware version %s", version); + sdsSensor.setQueryReportingMode(); sds011_sleep(); // we do sleep/wakup by ourselves + return true; } // reading data: void sds011_loop() { if (isSDS011Active) { - int sdsErrorCode = sdsSensor.read(&pm25, &pm10); - if (sdsErrorCode) { + PmResult pm = sdsSensor.queryPm(); + if (!pm.isOk()) { pm25 = pm10 = 0.0; - ESP_LOGI(TAG, "SDS011 error: %d", sdsErrorCode); + ESP_LOGE(TAG, "SDS011 query error"); } else { + pm25 = pm.pm25; + pm10 = pm.pm10; ESP_LOGI(TAG, "fine-dust-values: %5.1f,%4.1f", pm10, pm25); } sds011_sleep(); } - return; } // retrieving stored data: @@ -49,17 +55,15 @@ void sds011_store(sdsStatus_t *sds_store) { // putting the SDS-sensor to sleep void sds011_sleep(void) { - sdsSensor.sleep(); - isSDS011Active = false; + WorkingStateResult state = sdsSensor.sleep(); + isSDS011Active = state.isWorking(); } // start the SDS-sensor // needs 30 seconds for warming up void sds011_wakeup() { - if (!isSDS011Active) { - sdsSensor.wakeup(); - isSDS011Active = true; - } + WorkingStateResult state = sdsSensor.wakeup(); + isSDS011Active = state.isWorking(); } #endif // HAS_SDS011