function submitValue(type,id,param,val)
- if web_url then
+ val = tonumber(val)
+
+ if web_url and val then
local url = web_url.."?stype="..url_encode(type).."&sid="..url_encode(id).."¶m="..url_encode(param).."&value="..url_encode(val)
return req_sock
end})
- if code ~= 200 then
- print("writing record to backlog...")
+ if code ~= 200 and backlog_con then
+ printLog("writing record to backlog...")
backlog_con:execute(string.format("INSERT INTO queue(time_stamp,sensor_id,sensor,param,value) VALUES (datetime('now','localtime'),'%s','%s','%s',%f)",id,type,param,val))
end
return
end
+serialin:setvbuf('no')
+
records = {}
while 1 do
+
line=serialin:read("*l")
+
if line == nil then
break
end
- printLog("Received: "..line);
- if startswith(line,'{') then
- processJson(line)
- else
- processLine(line)
- end
- if dump_file then
- local f = io.open(dump_file,"w")
- io.output(f)
- io.write(json.encode(records))
- io.close(f)
- end
+ pcall(function ()
+
+ printLog("Received: "..line)
+ if startswith(line,'{') then
+ processJson(line)
+ else
+ processLine(line)
+ end
+
+ if dump_file then
+ local f = io.open(dump_file,"w")
+ io.output(f)
+ io.write(json.encode(records))
+ io.close(f)
+ end
+ end)
+
end