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 web_iface = cur.get(config,"web","iface")
17 io.input("/sys/class/net/"..web_iface.."/address")
19 io.input("/sys/class/net/eth0/address")
22 mac = io.read("*line")
23 mac = mac:gsub(":","")
26 web_devid = web_devid or mac
27 logging = cur.get(config,"logging","enabled")
29 serial_port = cur.get(config,"serial","port")
30 serial_baud = cur.get(config,"serial","baud")
32 command = "stty -F "..serial_port.." "..serial_baud
40 socket.select(nil, nil, sec)
43 function splitStr(str,char)
55 res[idx]=str:sub(1,pos-1)
65 function printLog(str)
68 os.execute("logger -t weathermon "..str)
72 function submitValue(type,id,param,val)
74 url = web_url.."?stype="..type.."&sid="..id.."¶m="..param.."&value="..val
79 command = command.." --interface "..web_iface
83 command = command.." -u "..web_user..":"..web_pass
86 command = command.." \""..url.."\""
94 function processLine(str)
96 msg=splitStr(line,':')
97 msg_type=msg[1] or nil
98 msg_body=msg[2] or nil
99 if msg_type=="STATUS" then
100 printLog("Status: "..msg_body)
101 elseif msg_type=="ERROR" then
102 printLog("Error: "..msg_body)
103 elseif msg_type=="SENSOR" then
104 printLog("SENSOR: "..msg_body)
105 sens = splitStr(msg_body,",")
109 sensor_id = web_devid
110 for i,rec in ipairs(sens) do
111 recrd=splitStr(rec,'=')
113 value=recrd[2] or nil
117 elseif key=="ID" then
124 for k,v in pairs(sensor) do
125 printLog("Type = "..sensor_type..", ID = "..sensor_id..", Param = "..k..", Value = "..v)
126 submitValue(sensor_type,sensor_id,k,v)
134 serialin=io.open(serial_port,"r")