return str
end
+function capture(cmd, raw)
+ local f = assert(io.popen(cmd, 'r'))
+ local s = assert(f:read('*a'))
+ f:close()
+ if raw then return s end
+ s = string.gsub(s, '^%s+', '')
+ s = string.gsub(s, '%s+$', '')
+ s = string.gsub(s, '[\n\r]+', ' ')
+ return s
+end
+
function mqtt_encode(str)
if (str) then
str = string.gsub (str, "\n", "")
if serial_port then
command = "stty -F "..serial_port.." "..serial_baud
- os.capture(command)
+ capture(command)
end
function printLog(str)
if logging=="on" then
- os.execute("logger -t weathermon "..str)
+ capture("logger -t weathermon "..str)
else
print(str)
end
command = command.." \""..url.."\""
- os.execute(command)
+ result = capture(command)
end
for key,value in pairs(msg) do
if value then
- if key=="model" then
+ if key=="model" or key=="device" then
sensor_type=value
elseif key=="id" then
sensor_id=value
end
if not (sensor_type==nil or sensor_id==nil or sensor_type=='' or sensor_id=='') then
+ if next(sensor)==nil then
+ sensor["command"]="alarm"
+ end
for k,v in pairs(sensor) do
printLog("Type = "..sensor_type..", ID = "..sensor_id..", Param = "..k..", Value = "..v)
submitValue(sensor_type,sensor_id,k,v)
" \""..string.gsub(alarm_type,"\"","\\\"")..
"\" \""..string.gsub(alarm_id,"\"","\\\"")..
"\" \""..string.gsub(msg_body,"\"","\\\"").."\""
- os.execute(command)
+ capture(command)
end
else
printLog("Cannot parse alarm input: "..msg_body)