summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2022-05-21 20:28:51 +0200
committerDaniel Friesel <derf@finalrewind.org>2022-05-21 20:28:51 +0200
commita53edf85913d8f12e0640606dc61873d9b3e8745 (patch)
treebed1fe194702dddd998ed21a30e3f006135ec59b
parent7f1fb35c9b18b723c34b2a9d42e804234bae0c1e (diff)
document report mode query; save queried report mode in sds011 table
-rw-r--r--README.md10
-rw-r--r--sds011.lua9
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