openwrt: index tables by x, not by the contents of the variable x
This commit is contained in:
parent
ce102cfb54
commit
4a7ae875ec
|
@ -109,18 +109,18 @@ function buffer(child, interval)
|
||||||
end
|
end
|
||||||
|
|
||||||
if msec then -- we're dealing with a pls xxx:yyy:zzz message so calculate power
|
if msec then -- we're dealing with a pls xxx:yyy:zzz message so calculate power
|
||||||
if prev[meter][msec] then
|
if prev[meter].msec then
|
||||||
local power = diff(prev[meter][value], value) / diff(prev[meter][msec], msec)
|
local power = math.floor(diff(prev[meter].value, value) / diff(prev[meter].msec, msec) * 3.6 * 10^6 + 0.5)
|
||||||
prev[meter][value] = value
|
prev[meter].value = value
|
||||||
value = power
|
value = power
|
||||||
else
|
else
|
||||||
prev[meter][value] = value
|
prev[meter].value = value
|
||||||
value = nil
|
value = nil
|
||||||
end
|
end
|
||||||
prev[meter][msec] = msec
|
prev[meter].msec = msec
|
||||||
end
|
end
|
||||||
|
|
||||||
if timestamp > math.max(1234567890, prev[meter][timestamp] or 0) and value then
|
if timestamp > math.max(1234567890, prev[meter].timestamp or 0) and value then
|
||||||
measurements:add(meter, timestamp, value)
|
measurements:add(meter, timestamp, value)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -128,7 +128,7 @@ function buffer(child, interval)
|
||||||
if timestamp > threshold and 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 = timestamp + interval
|
threshold = timestamp + interval
|
||||||
prev[meter][timestamp] = timestamp
|
prev[meter].timestamp = timestamp
|
||||||
end
|
end
|
||||||
meter, timestamp, value, msec = coroutine.yield()
|
meter, timestamp, value, msec = coroutine.yield()
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue