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
" \""..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)