5 local uci=require("uci")
7 local config="weathermon"
9 web_url = cur.get(config,"web","url")
10 web_user = cur.get(config,"web","user")
11 web_pass = cur.get(config,"web","password")
12 web_devid = cur.get(config,"web","devid")
14 io.input("/sys/class/net/eth0/address")
15 mac = io.read("*line")
16 mac = mac:gsub(":","")
19 web_devid = web_devid or mac
21 logging = cur.get(config,"logging","enabled")
28 socket.select(nil, nil, sec)
31 function splitStr(str,char)
43 res[idx]=str:sub(1,pos-1)
53 function printLog(str)
56 os.execute("logger -t weathermon "..str)
60 function submitValue(type,id,param,val)
62 printLog("URL="..web_url)
64 url = web_url.."?stype="..type.."&sid="..id.."¶m="..param.."&value="..val
71 command = command.." -u "..web_user..":"..web_pass
74 command = command.." \""..url.."\""
76 printLog("COMMAND=\""..command.."\"")
82 function processLine(str)
84 msg=splitStr(line,':')
85 msg_type=msg[1] or nil
86 msg_body=msg[2] or nil
87 if msg_type=="STATUS" then
88 printLog("Status: "..msg_body)
89 elseif msg_type=="ERROR" then
90 printLog("Error: "..msg_body)
91 elseif msg_type=="SENSOR" then
92 printLog("SENSOR: "..msg_body)
93 sens = splitStr(msg_body,",")
98 for i,rec in ipairs(sens) do
99 recrd=splitStr(rec,'=')
101 value=recrd[2] or nil
105 elseif key=="ID" then
112 for k,v in pairs(sensor) do
113 printLog("Type = "..sensor_type..", ID = "..sensor_id..", Param = "..key..", Value = "..value)
114 submitValue(sensor_type,sensor_id,key,value)