From ed4e01ce8da388ad31c25e1f51eafb95925e4da8 Mon Sep 17 00:00:00 2001 From: Bart Van Der Meerssche Date: Wed, 21 Apr 2010 00:07:47 +0200 Subject: [PATCH] fixes bugs in data module for the daemons pwr chain --- openwrt/package/flukso/src/data.lua | 18 +++++++++--------- openwrt/package/flukso/src/flukso.lua | 4 ++-- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/openwrt/package/flukso/src/data.lua b/openwrt/package/flukso/src/data.lua index 2662b29..be20c3f 100644 --- a/openwrt/package/flukso/src/data.lua +++ b/openwrt/package/flukso/src/data.lua @@ -20,11 +20,11 @@ -- $Id$ -- -local os, math, table = - os, math, table +local os, math, table, string = + os, math, table, string -local getfenv, setmetatable, pairs = - getfenv, setmetatable, pairs +local getfenv, setmetatable, pairs, ipairs = + getfenv, setmetatable, pairs, ipairs module (...) local modenv = getfenv() -- module environment @@ -78,19 +78,19 @@ function fill(M) end function json_encode(M) - J = {} + local J = {} for meter, T in pairs(M) do J[meter] = '[' local H = timestamps(T) - for i = H[1], H[#H] do - J[meter] = J[meter] .. '[' .. T[i] .. ']' + for k, timestamp in ipairs(H) do + J[meter] = J[meter] .. '[' .. timestamp .. ',' .. T[timestamp] .. '],' end - J[meter] = J[meter] .. ']' + J[meter] = string.sub(J[meter], 1, -2) .. ']' end return J end -local function timestamps(T) +function timestamps(T) local H = {} -- helper table, an indexed array containing all the measurement's timestamps for timestamp in pairs(T) do H[#H+1] = timestamp end table.sort(H) -- sort in ascending order, oldest timestamps will be treated first diff --git a/openwrt/package/flukso/src/flukso.lua b/openwrt/package/flukso/src/flukso.lua index 9f8de77..989ca4b 100755 --- a/openwrt/package/flukso/src/flukso.lua +++ b/openwrt/package/flukso/src/flukso.lua @@ -35,7 +35,7 @@ local param = {xmlrpcaddress = 'http://logger.flukso.net/xmlrpc', pwraddress = '255.255.255.255', pwrport = 26488, pwrenable = false, - pwrinterval = 1, + pwrinterval = 0, pwrdir = '/tmp/sensor', device = '/dev/ttyS0', interval = 300} @@ -164,7 +164,7 @@ function publish(child, dir) os.execute('mkdir -p ' .. dir .. ' > /dev/null') while true do local measurements_json = measurements:json_encode() - for meter, json in measurements_json do + for meter, json in pairs(measurements_json) do io.output(dir .. '/' .. meter) io.write(json) io.close()