Skip to content

Commit

Permalink
get 2 messages, process the 1st
Browse files Browse the repository at this point in the history
  • Loading branch information
avaldebe committed Dec 6, 2015
1 parent f585f7a commit 29a4302
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions lua_modules/pms3003.lua
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,17 @@ function M.read(callBack)
('%s.init %s argument should be %s'):format(M.name,'1st','function'))

-- capture and decode message
uart.on('data',M.mlen,function(data)
uart.on('data',M.mlen*2,function(data)
local bm=data:find("BM")
if bm then
-- stop sampling time-out timer
tmr.stop(4)
tmr.stop(4)
-- decode message
decode(data:sub(1,M.mlen))
decode(data:sub(bm,M.mlen+bm-1))
-- restore UART & callBack
M.init(nil,nil,'finished')
if type(callBack)=='function' then callBack() end
M.init(nil,nil,'finished')
if type(callBack)=='function' then callBack() end
end
end,0)

-- start sampling: continuous sampling mode
Expand All @@ -128,8 +131,8 @@ function M.read(callBack)
end
gpio.write(pinSET,gpio.HIGH)

-- sampling time-out: 1s after sampling started
tmr.alarm(4,1000,0,function()
-- sampling time-out: 2s after sampling started
tmr.alarm(4,2000,0,function()
M.pm01,M.pm25,M.pm10=nil,nil,nil
-- restore UART & callBack
M.init(nil,nil,'failed')
Expand Down

0 comments on commit 29a4302

Please sign in to comment.