User Tools

Site Tools


get_weather_conditions_and_forecast

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
get_weather_conditions_and_forecast [2019/01/09 10:42] – [Weather and resource monitoring] akuzmukget_weather_conditions_and_forecast [2023/02/20 10:28] (current) emozolyak
Line 1: Line 1:
 ===== Weather conditions and forecast functions ===== ===== Weather conditions and forecast functions =====
  
 +
 +<WRAP center round important 60%>
 +You must have Level2 [[level2:how_to_connect_webhmi_to_level2#services|weather forecasting service]] activated to use this function.
 +</WRAP>
  
 ==== GetCurrentWeather() ==== ==== GetCurrentWeather() ====
Line 64: Line 68:
 The service requires an Internet connection, an account in Level2 and a subscription to the weather forecast. The function is available since version 2.5.2400. The service requires an Internet connection, an account in Level2 and a subscription to the weather forecast. The function is available since version 2.5.2400.
 If for some reason the data has not been received, the value nil will be returned. If for some reason the data has not been received, the value nil will be returned.
 +
 +===== One more example =====
 +
 +<code lua>
 +---------------------------- TIMER ----------------------------
 +fiveMinTimer = {}
 +setmetatable(fiveMinTimer, {
 +    __call = function (self) 
 +                self.DELAY = 2
 +                local t = os.date("*t"   
 +                local ifTimeBoundary = (t.min % self.DELAY == 0) and true or false 
 +
 +                if (ifTimeBoundary and not self.lock) then 
 +                    self.lock = true             
 +                    return true 
 +                end 
 +                
 +                if (self.lock and not ifTimeBoundary) then 
 +                    self.lock = false 
 +                    DEBUG("released lock")
 +                end 
 +                return false 
 +             end 
 +})
 +
 +---------------------------- MAIN ---------------------------- 
 +function main (userId)
 +
 +  if fiveMinTimer() then  
 +      weatherDemoLevel2() 
 +  end 
 +  
 +end
 +
 +---------------------------- HELPERS ---------------------------
 +
 +-- invokes all functions related to weather 
 +function weatherDemoLevel2() 
 +
 +    local wdata = GetCurrentWeather()     
 +    tprint(wdata)
 +    --[[
 +        The GetCurrentWeather function returns the current weather conditions at the WebHMI installation location. 
 +        The data is being updated approximately every two hours. The service requires an Internet connection, 
 +        an account in Level2 and a subscription to the weather forecast. The function is available since version 2.5.2400.
 +        If for some reason the data has not been received, the value nil will be returned.
 +    --]]
 +
 +    wdata = GetForecastWeather(5)
 +    tprint(wdata)
 +    --[[
 +        The GetForecastWeather function returns the weather forecast at the WebHMI installation location to the specified interval. 
 +        The data is updated approximately every two hours. The service requires an Internet connection, an account in Level2 and a
 +        subscription to the weather forecast. The function is available since version 2.5.2400.
 +        If for some reason the data has not been received, the value nil will be returned.
 +        The interval is a three-hour time interval in the future. From zero to 6. Total six intervals. Zero interval is the forecast in about 3 hours. The first interval is the forecast in six hours. Etc. The format of the returned data is identical to the function GetCurrentWeather.
 +    --]]
 +    
 +    wdata = GetSunriseTime(4)  
 +    INFO(os.date("%X", wdata) ) 
 +    --[[ The function GetSunriseTime returns the time in the format Unixtime of the sunrise in the current day. The service requires an
 +          Internet connection, an account in Level2 and a subscription to the weather forecast. The function is available since version 2.5.2400.
 +          If for some reason the data has not been received, the value nil will be returned.
 +    --]] 
 +    
 +    wdata = GetSunsetTime(3) 
 +    INFO(os.date("%X", wdata) )
 +  --[[ The function GetSunsetTime returns the time in Unixtime format of sunset in the current day. 
 +        The service requires an Internet connection, an account in Level2 and a subscription to the weather forecast. 
 +        The function is available since version 2.5.2400. If for some reason the data has not been received, the value nil will be returned.
 +   --]]
 +
 +end 
 +
 +-- prints a table 
 +function tprint(t, indent)
 +    if not indent then indent = 0 end 
 +    for k, v in pairs(t) do 
 +        local formatting = string.rep(' ', indent) .. k .. ': '
 +        if type(v) == "table" then 
 +            ERROR(formatting) 
 +            tprint(v, indent + 1) -- recursive call 
 +        else
 +            if type(v) == "boolean" then 
 +                v = v and "TRUE" or "FALSE"
 +            end 
 +            ERROR(formatting .. v) 
 +        end 
 +    end  
 +end 
 +
 +
 +
 +
 +</code>
  
  
get_weather_conditions_and_forecast.1547030525.txt.gz · Last modified: 2019/01/09 10:42 by akuzmuk

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki