I'm kinda stuck with the curl-part in the "IsItGonnaRain" function. (see this topic)
This scripts gets data from "Buienradar" and should save this into a tmp file
Next it should read this file line by line to process the data.
I am under the impression that the data/file is not saved actually.
Being no-expert in LUA, some help will be very welcome
here's part of my code
Code: Select all
function IsItGonnaRain(latitude,longitude,tempfilename,minutesinfuture,debug)
local averagerain = 0
local totalrain = 0
local rainlines = 0
-- construct the request URL
local url = 'http://gps.buienradar.nl/getrr.php?lat='..latitude..'&lon='..longitude
if (debug == 1) then print("| Request URL .............. : " .. url) end
-- now get the data
local trigger_action = 'curl -o '..tempfilename..' "'..url..'"' -- -s for Silent (no error messages) and -o for Write output to file instead of stdout.
handle = os.execute(trigger_action)
if (debug == 1) then
print("| Trigger action ........... : " .. trigger_action)
if handle then
print("| CURL Data request ........ : Success")
else
print("! CURL Data request ........ : Failed")
end
end
file = io.open(tempfilename, "r")
-- now analyse the received lines, format is like 000|15:30 per line.
while true do
line = file:read("*line")
if not line then break end
if (debug == 1) then print("| Rain data (line) ......... : " .. line) end
end
Here's the debug result
Code: Select all
2016-08-29 23:56:00.509 LUA: +--------------------------------------------------+
2016-08-29 23:56:00.509 LUA: | =============== IS IT GONNA RAIN =============== |
2016-08-29 23:56:00.509 LUA: +--------------------------------------------------+
2016-08-29 23:56:00.509 LUA: | Request URL .............. : http://gps.buienradar.nl/getrr.php?lat=52.326080&lon=5.600445
2016-08-29 23:56:00.595 LUA: | Trigger action ........... : curl -o /home/pi/domoticz/scripts/tmp/rain.tmp "http://gps.buienradar.nl/getrr.php?lat=52.326080&lon=5.600445"
2016-08-29 23:56:00.596 LUA: | CURL Data request ........ : Success
2016-08-29 [color=#FF0000]23:56[/color]:00.596 LUA: | Rain data (line) ......... : 000|[color=#FF0000]19:45[/color]
2016-08-29 23:56:00.596 LUA: | Rain data # lines ........ : 0
2016-08-29 23:56:00.596 LUA: | Total rain ............... : 0