From a53edf85913d8f12e0640606dc61873d9b3e8745 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Sat, 21 May 2022 20:28:51 +0200 Subject: document report mode query; save queried report mode in sds011 table --- README.md | 10 +++++++--- sds011.lua | 9 ++++++--- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 1f3c839..f7e8505 100644 --- a/README.md +++ b/README.md @@ -64,13 +64,17 @@ If desired, **sds011.lua** can be used to configure the SDS011 sensor. Currently, the following commands are supported * `port:write(sds011.set_report_mode(active))` + * active == nil: request current mode; do not change it. + The mode can be read from `sds011.active_mode` after a few milliseconds. * active == true: periodically report PM2.5 and PM10 values via UART * active == false: only report PM2.5 and PM10 values when queried * `port:write(sds011.sleep(sleep))` - * sleep == true: put sensor into sleep mode. The fan is turned off, no further measurements are performed - * sleep == false: wake up sensor. + * sleep == true: put sensor into sleep mode. + The fan is turned off, no further measurements are performed. + * sleep == false: wake up sensor * `port:write(sds011.set_work_period(period))` - * period == nil: request current work period; does not change it + * period == nil: request current work period; do not change it. + The work period can be read from `sds011.work_period` after a few milliseconds. * period == 0: continuous operation (about one measurement per second) * 0 < *period* ≤ 30: about one measurement every *period* minutes; fan turned off in-between diff --git a/sds011.lua b/sds011.lua index 8d5dd58..44b965b 100644 --- a/sds011.lua +++ b/sds011.lua @@ -18,7 +18,8 @@ local c_sleep = 0x00 local c_work = 0x01 local c_workperiod = 0x08 -sds011.work_period = 0 +sds011.work_period = nil +sds011.active_mode = nil function sds011.finish_cmd(cmd) cmd = cmd .. string.char(0xff, 0xff) @@ -90,8 +91,10 @@ function sds011.parse_frame(data) sds011.pm10i = pm10 / 10 sds011.pm10f = pm10 % 10 return true - end - if command == 0xc5 and pm25l == 0x08 then + elseif command == 0xc5 and pm25l == 0x02 then + sds011.active_mode = pm10l == 0 + return true + elseif command == 0xc5 and pm25l == 0x08 then sds011.work_period = pm10l return true end -- cgit v1.2.3