From 9b024ef6c2d9a1f8260fadd562f8d2298a50eb3e Mon Sep 17 00:00:00 2001 From: Roman Bazalevsky Date: Sat, 28 Mar 2020 18:43:30 +0300 Subject: [PATCH] =?utf8?q?=D0=9A=D0=BE=D1=80=D1=80=D0=B5=D0=BA=D1=82=D0=BD?= =?utf8?q?=D0=BE=D0=B5=20=D0=B7=D0=B0=D0=BA=D1=80=D1=8B=D1=82=D0=B8=D0=B5?= =?utf8?q?=20=D0=BA=D1=83=D1=80=D1=81=D0=BE=D1=80=D0=B0=20=D0=BF=D0=BE?= =?utf8?q?=D1=81=D0=BB=D0=B5=20=D0=B2=D1=8B=D0=BF=D0=BE=D0=BB=D0=BD=D0=B5?= =?utf8?q?=D0=BD=D0=B8=D1=8F=20=D0=B7=D0=B0=D0=BF=D1=80=D0=BE=D1=81=D0=B0.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- bin/weather-lcd | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/bin/weather-lcd b/bin/weather-lcd index 9abd84f..d3283ca 100755 --- a/bin/weather-lcd +++ b/bin/weather-lcd @@ -19,7 +19,7 @@ graph_duration = uci.get(config_name,"display","graph_duration") if graph_duration and not(weather_db == "") then pcall(function () local dbdriver = require "luasql.sqlite3" - local env = assert(dbdriver.sqlite3()) + env = assert(dbdriver.sqlite3()) log_con = assert(env:connect(weather_db)) end) end @@ -193,8 +193,8 @@ function process_graphs() local sensor = def["sensor"] local param = def["param"] local pageid = sensor.."."..param - local cur = assert (log_con:execute(string.format("select hour,avg(value) val from (select strftime('%%Y-%%m-%%d %%H',time_stamp)||':00' hour,value from log where sensor='%s' and param='%s') group by hour order by hour desc limit 24",sensor,param))) - local row = cur:fetch ({}, "a") + local sqlcur = assert (log_con:execute(string.format("select hour,avg(value) val from (select strftime('%%Y-%%m-%%d %%H',time_stamp)||':00' hour,value from log where sensor='%s' and param='%s') group by hour order by hour desc limit 24",sensor,param))) + local row = sqlcur:fetch ({}, "a") local vals = {} local maxval = -99999999 local minval = 99999999 @@ -202,7 +202,7 @@ function process_graphs() for k=width,1,-1 do if row then val = row["val"] * def["scale"] - row = cur:fetch ({}, "a") + row = sqlcur:fetch ({}, "a") else val = nil end @@ -210,6 +210,7 @@ function process_graphs() if val and (val > maxval) then maxval = val; end if val and (val < minval) then minval = val; end end + sqlcur:close() minval = math.floor(minval) maxval = math.ceil(maxval) if height>2 then @@ -251,18 +252,18 @@ setup_pages(conn) while true do - pcall( function () +-- pcall( function () vals = process_file() process_vals(vals) - if log_con then + if weather_db then process_graphs() end os.execute("inotifywait -e MODIFY \""..weather_file.."\"") - end) +-- end) socket.sleep(3) -- 2.34.1