openwrt: support pls xxx:yyy:zzz type messages with zzz = 32-bit millisec counter on the AVR
This commit is contained in:
parent
431fefa5f2
commit
8f4e7a17a2
|
@ -41,42 +41,54 @@ local param = {xmlrpcaddress = 'http://logger.flukso.net/xmlrpc',
|
||||||
|
|
||||||
function dispatch(e_child, p_child, device, pwrenable)
|
function dispatch(e_child, p_child, device, pwrenable)
|
||||||
return coroutine.create(function()
|
return coroutine.create(function()
|
||||||
|
|
||||||
|
local function flash() -- flash the power led for 50ms
|
||||||
|
os.execute('gpioctl clear 4 > /dev/null')
|
||||||
|
socket.select(nil, nil, 0.05)
|
||||||
|
os.execute('gpioctl set 4 > /dev/null')
|
||||||
|
end
|
||||||
|
|
||||||
-- open the connection to the syslog deamon, specifying our identity
|
-- open the connection to the syslog deamon, specifying our identity
|
||||||
posix.openlog('flukso')
|
posix.openlog('flukso')
|
||||||
posix.syslog(30, 'starting the flukso deamon')
|
posix.syslog(30, 'starting the flukso deamon')
|
||||||
posix.syslog(30, 'listening for pulses on '..device..'...')
|
posix.syslog(30, 'listening for pulses on '..device..'...')
|
||||||
|
|
||||||
|
pattern = '^(%l+)%s(%x+):(%d+):?(%d*)$'
|
||||||
|
|
||||||
for line in io.lines(device) do
|
for line in io.lines(device) do
|
||||||
if line:sub(1, 3) == 'pls' and line:len() == 47 and line:find(':') == 37 then -- user data + additional data integrity checks
|
command, meter, value, millis = line:match(pattern)
|
||||||
posix.syslog(30, 'received pulse from '..device..': '..line:sub(5))
|
length = line:len()
|
||||||
|
|
||||||
-- flash the power led for 50ms
|
if command == 'pls' and (length == 47 or length == 58) then -- user data
|
||||||
os.execute('gpioctl clear 4 > /dev/null')
|
flash()
|
||||||
socket.select(nil, nil, 0.05)
|
posix.syslog(30, 'received pulse from ' .. device .. ': ' .. line:sub(5))
|
||||||
os.execute('gpioctl set 4 > /dev/null')
|
|
||||||
|
|
||||||
local meter, value = line:sub(5, 36), tonumber(line:sub(38))
|
coroutine.resume(e_child, meter, os.time(), tonumber(value))
|
||||||
coroutine.resume(e_child, meter, os.time(), value)
|
|
||||||
|
|
||||||
elseif line:sub(1, 3) == 'pwr' and line:len() == 47 and line:find(':') == 37 then -- user data + additional data integrity checks
|
-- pls includes a msec timestamp so report to p_child as well
|
||||||
local meter, value = line:sub(5, 36), tonumber(line:sub(38))
|
if length == 58 then
|
||||||
|
coroutine.resume(p_child, meter, os.time(), nil, tonumber(millis))
|
||||||
|
end
|
||||||
|
|
||||||
|
elseif command == 'pwr' and length == 47 then -- user data
|
||||||
if pwrenable then coroutine.resume(p_child, meter, os.time(), value) end
|
if pwrenable then coroutine.resume(p_child, meter, os.time(), value) end
|
||||||
|
|
||||||
elseif line:sub(1, 3) == 'msg' then -- control data
|
elseif command == 'msg' then -- control data
|
||||||
posix.syslog(31, 'received message from '..device..': '..line:sub(5))
|
posix.syslog(31, 'received message from ' .. device .. ': ' .. line:sub(5))
|
||||||
|
|
||||||
else
|
else -- error
|
||||||
posix.syslog(27, 'input error on '..device..': '..line)
|
posix.syslog(27, 'input error on ' .. device .. ': ' .. line)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
posix.syslog(30, 'closing down the flukso deamon')
|
posix.syslog(30, 'closing down the flukso deamon')
|
||||||
os.exit()
|
os.exit(1)
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- TODO: adapt for millis input
|
||||||
function buffer(child, interval)
|
function buffer(child, interval)
|
||||||
return coroutine.create(function(meter, timestamp, value)
|
return coroutine.create(function(meter, timestamp, value, millis)
|
||||||
local measurements = data.new()
|
local measurements = data.new()
|
||||||
local threshold = timestamp + interval
|
local threshold = timestamp + interval
|
||||||
local timestamp_prev = {}
|
local timestamp_prev = {}
|
||||||
|
|
Loading…
Reference in New Issue