I have tried to modifie the script under to work under Windows I changed the include path of the JSON parser file but I still gives me an error, the file is there and the name is exactly the same. Could this be the curl part and how would I go about changing it?
From log:
2016-03-09 08:43:00.070 Error: EventSystem: in C:\Program Files (x86)\Domoticz\scripts\lua\script_time_eta.lua: ...ram Files (x86)\Domoticz\scripts\lua\script_time_eta.lua:50: attempt to index local 'jsonTrajet' (a nil value)
The code:
Code: Select all
--C:\Program Files (x86)\Domoticz\scripts\lua\script_time_eta.lua
------------- Begin time functions -------------
function timedifference_lastupdate_homework (s)
if s == nil then
print('Error: Could not get lastupdate from device')
difference = 1000 --value have to be larger than timeout. new virtual devices don't get corrent lastupdate value, skips the first check
return difference
end
year = string.sub(s, 1, 4)
month = string.sub(s, 6, 7)
day = string.sub(s, 9, 10)
hour = string.sub(s, 12, 13)
minutes = string.sub(s, 15, 16)
seconds = string.sub(s, 18, 19)
t1 = os.time()
t2 = os.time{year=year, month=month, day=day, hour=hour, min=minutes, sec=seconds}
difference = os.difftime (t1, t2)
return difference
end
------------- End time functions -------------
------------- Begin local variables -------------
-- Debug variables:
timeout = 300
difference_homework = timedifference_lastupdate_homework(otherdevices_lastupdate['ETA']) --change to the name of the virtual device
------------- End local variables -------------
------------- Begin code -------------
commandArray = {}
if (difference_homework > timeout)
then
function traveltime(departx,departy,arrivex,arrivey)
--get route from WAZE--
local waze=assert(io.popen('curl "https://www.waze.com/row-RoutingManager/routingRequest?from=x%3A'..departx..'+y%3A'..departy..'&to=x%3A'..arrivex..'+y%3A'..arrivey..'&returnJSON=true&returnGeometries=true&returnInstructions=true&timeout=60000&nPaths=1&clientVersion=4.0.0&options=AVOID_TRAILS%3At%2CALLOW_UTURNS"'))
local trajet = waze:read('*all')
waze:close()
local jsonTrajet = json:decode(trajet)
--Get major road from JSON
routeName = jsonTrajet['response']['routeName']
--Get route steps from JSON info
route = jsonTrajet['response']['results']
--Calculate the total time by adding the time of all sections
routeTotalTimeSec = 0
for response,results in pairs(route) do
routeTotalTimeSec = routeTotalTimeSec + results['crossTime']
end
--translate the number of seconds to minutes
routeTotalTimeMin = routeTotalTimeSec/60-((routeTotalTimeSec%60)/60)
return routeTotalTimeMin
end
--import JSON addin (download from http://regex.info/code/JSON.lua)
json = (loadfile "C:\\Program Files (x86)\\Domoticz\\scripts\\lua\\JSON.lua")()
-- Update these variables ---------------
--idx of virtual device for capturing the travel minutes
idxhomework = '68'
departy="59.684534" --lat
departx="9.627667" --long
arrivey="59.675331" --lat
arrivex="9.641017" --long
-- get travel time
homework=traveltime(departx,departy,arrivex,arrivey)
commandArray[1] = {['UpdateDevice'] = idxhomework .. '|0|' .. homework}
end
------------- End code -------------
return commandArray
Robert