summaryrefslogtreecommitdiff
path: root/mh-z19.lua
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2022-05-25 21:44:57 +0200
committerDaniel Friesel <derf@finalrewind.org>2022-05-25 21:44:57 +0200
commitee6a1033c293f3d3b327568fe9554d4651c4c964 (patch)
treec49d6071cd0d2587553492a31280687eb34b0c77 /mh-z19.lua
initial commit
Diffstat (limited to 'mh-z19.lua')
-rw-r--r--mh-z19.lua28
1 files changed, 28 insertions, 0 deletions
diff --git a/mh-z19.lua b/mh-z19.lua
new file mode 100644
index 0000000..fe269b8
--- /dev/null
+++ b/mh-z19.lua
@@ -0,0 +1,28 @@
+local mhz19 = {}
+
+local c_read = string.char(0xff, 0x01, 0x86, 0x00, 0x00, 0x00, 0x00, 0x00, 0x79)
+
+mhz19.co2 = nil
+mhz19.temp = nil
+mhz19.tt = nil
+mhz19.ss = nil
+mhz19.uu = nil
+
+function mhz19.query()
+ return c_read
+end
+
+function mhz19.parse_frame(data)
+ local head, cmd, co2h, co2l, temp, tt, ss, uh, ul = struct.unpack("BBBBBBBBB", data)
+ if head ~= 0xff or cmd ~= 0x86 then
+ return false
+ end
+ mhz19.co2 = co2h * 256 + co2l
+ mhz19.temp = temp - 40
+ mhz19.tt = tt
+ mhz19.ss = ss
+ mhz19.uu = uh * 256 + ul
+ return true
+end
+
+return mhz19