3 local json = require("json")
4 local socket = require("socket")
5 local http = require("socket.http")
9 function getConfig(configname)
13 local uci=require("uci")
14 local cur=uci.cursor()
22 web_url = cur.get(config,"web","url")
23 web_user = cur.get(config,"web","user")
24 web_timeout = cur.get(config,"web","timeout")
25 web_pass = cur.get(config,"web","password")
27 if not web_timeout then
31 backlogdb = cur.get(config,"process","backlogdb")
35 function submitValue(timestamp,type,id,param,val)
37 local url = web_url.."?stype="..url_encode(type).."&sid="..url_encode(id).."¶m="..url_encode(param).."&value="..url_encode(val).."&time="..url_encode(timestamp)
40 url = url:gsub("//","//"..web_user..":"..web_pass.."@",1)
43 local result,code = http.request ({
44 url=url, create=function()
45 local req_sock = socket.tcp()
46 req_sock:settimeout(web_timeout)
62 local dbdriver = require "luasql.sqlite3"
63 env = assert(dbdriver.sqlite3())
64 if file_exists(backlogdb) then
65 backlog_con = assert(env:connect(backlogdb))
68 cursor = assert(backlog_con:execute("SELECT rowid,time_stamp,sensor_id,sensor,param,value FROM queue LIMIT 400"))
69 row = cursor:fetch ({}, "a")
71 if submitValue(row.time_stamp,row.sensor,row.sensor_id,row.param,row.value) then
72 backlog_con:execute(string.format("DELETE FROM queue WHERE rowid='%s'",row.rowid))
74 row = cursor:fetch (row, "a")