From aacadda01d9727b6e98e7a119f5b7a4e380f2aab Mon Sep 17 00:00:00 2001 From: August Quint <49277349+AugustQu@users.noreply.github.com> Date: Tue, 21 Jan 2020 14:56:02 +0100 Subject: [PATCH] initial --- src/sds011read.cpp | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 src/sds011read.cpp diff --git a/src/sds011read.cpp b/src/sds011read.cpp new file mode 100644 index 00000000..c55b5741 --- /dev/null +++ b/src/sds011read.cpp @@ -0,0 +1,36 @@ +// routines for fetching data from the SDS011-sensor + +// Local logging tag +static const char TAG[] = __FILE__; + +#include + +// UART(2) is unused in this project +static HardwareSerial sdsSerial(2); // so we use it here +static SDS011 sdsSensor; // fine dust sensor + +// the results of the sensor: +float pm25; +float pm10; + +// init +bool sds011_init() +{ + pm25 = pm10 = 0.0; + sdsSerial.begin(9600, SERIAL_8N1, ESP_PIN_RX, ESP_PIN_TX); + sdsSensor.begin (&sdsSerial); + sdsSensor.contmode(0); // for safety: wakeup/sleep - if we want it we do it by ourselves + sdsSensor.wakeup(); // always wake up + return true; +} +// reading data: +void sds011_loop() +{ + pm25 = pm10 = 0.0; + int sdsErrorCode = sdsSensor.read(&pm25, &pm10); + if (!sdsErrorCode) + { + ESP_LOGD(TAG, "SDS011 error: %d", sdsErrorCode); + } + return; +}