diff options
author | Daniel Friesel <derf@finalrewind.org> | 2022-05-25 21:44:57 +0200 |
---|---|---|
committer | Daniel Friesel <derf@finalrewind.org> | 2022-05-25 21:44:57 +0200 |
commit | ee6a1033c293f3d3b327568fe9554d4651c4c964 (patch) | |
tree | c49d6071cd0d2587553492a31280687eb34b0c77 /mh-z19.lua |
initial commit
Diffstat (limited to 'mh-z19.lua')
-rw-r--r-- | mh-z19.lua | 28 |
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 |