[fluksod] we only have to publish once per second

This commit is contained in:
Bart Van Der Meerssche 2011-04-30 19:23:51 +02:00
parent e013ab81bb
commit 412cbc03e3
1 changed files with 4 additions and 1 deletions

View File

@ -79,6 +79,7 @@ local CACERT = FLUKSO.daemon.cacert
-- set LAN parameters -- set LAN parameters
local LAN_ENABLED = (FLUKSO.daemon.enable_lan_branch == '1') local LAN_ENABLED = (FLUKSO.daemon.enable_lan_branch == '1')
local LAN_INTERVAL = 0
local LAN_POLISH_CUTOFF = 60 local LAN_POLISH_CUTOFF = 60
local LAN_PUBLISH_PATH = DAEMON_PATH .. '/sensor' local LAN_PUBLISH_PATH = DAEMON_PATH .. '/sensor'
@ -264,6 +265,7 @@ end
function lan_buffer(child) function lan_buffer(child)
return coroutine.create(function(sensor_id, timestamp, power, counter, msec) return coroutine.create(function(sensor_id, timestamp, power, counter, msec)
local measurements = data.new() local measurements = data.new()
local threshold = os.time() + LAN_INTERVAL
local previous = {} local previous = {}
local function diff(x, y) -- calculates y - x local function diff(x, y) -- calculates y - x
@ -299,8 +301,9 @@ function lan_buffer(child)
end end
end end
if next(measurements) then --checking whether table is not empty if timestamp > threshold and next(measurements) then --checking whether table is not empty
coroutine.resume(child, measurements) coroutine.resume(child, measurements)
threshold = os.time() + LAN_INTERVAL
end end
sensor_id, timestamp, power, counter, msec = coroutine.yield() sensor_id, timestamp, power, counter, msec = coroutine.yield()