get_weather_conditions_and_forecast
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
get_weather_conditions_and_forecast [2019/01/09 10:34] – akuzmuk | get_weather_conditions_and_forecast [2023/02/20 10:28] (current) – emozolyak | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ===== Weather and resource monitoring | + | ===== Weather |
+ | |||
+ | |||
+ | <WRAP center round important 60%> | ||
+ | You must have Level2 [[level2: | ||
+ | </ | ||
+ | |||
+ | ==== GetCurrentWeather() ==== | ||
+ | |||
+ | 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. | ||
+ | |||
+ | The function returns a table with the following fields: | ||
+ | |||
+ | ^time | The time for which the weather data was received | | ||
+ | ^text | A short textual description of the current weather| | ||
+ | ^temperature | Air temperature in degrees Celsius| | ||
+ | ^pressure | Atmospheric pressure in hPa| | ||
+ | ^humidity | Relative air humidity in %| | ||
+ | ^windDirection | The direction of the wind origin, metrological degrees (north— 0 degrees)| | ||
+ | ^windSpeed | Wind speed in m/s| | ||
+ | ^cloudness | Covering the sky with clouds as a percentage| | ||
+ | ^rain | Precipitation (rain), in mm| | ||
+ | ^snow | Precipitation (snow), in mm| | ||
Line 44: | Line 69: | ||
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. | ||
- | ==== GetMeterConsumption(variable_name[, | + | ===== One more example ===== |
- | The GetMeterConsumption function returns the resource consumption for the specified counter. Parameters **variable_name** and // | + | |
- | Returned consumption of resources is the consumption of the meter for each hour from the beginning of the month to the current moment. Data is taken from Level2 times per hour. Why not from the local database? Because a) the data storage period on the SD card can be less than 1 month and b) because the SD card may fail and if it is replaced in the middle of the month, the data will be unreliable. | + | <code lua> |
+ | ---------------------------- TIMER ---------------------------- | ||
+ | fiveMinTimer = {} | ||
+ | setmetatable(fiveMinTimer, | ||
+ | __call = function (self) | ||
+ | self.DELAY = 2 | ||
+ | local t = os.date(" | ||
+ | | ||
- | The service requires an Internet connection, an account in Level2, | + | if (ifTimeBoundary |
+ | self.lock = true | ||
+ | return true | ||
+ | end | ||
+ | |||
+ | if (self.lock and not ifTimeBoundary) then | ||
+ | self.lock = false | ||
+ | DEBUG(" | ||
+ | end | ||
+ | return false | ||
+ | end | ||
+ | }) | ||
- | If for some reason the data has not been received, the value nil will be returned. | + | ---------------------------- MAIN ---------------------------- |
+ | function main (userId) | ||
- | ==== GetResourceLimit(resource_name) ==== | + | if fiveMinTimer() then |
+ | weatherDemoLevel2() | ||
+ | end | ||
+ | |||
+ | end | ||
- | The GetResourceLimit function returns the limit of the specified resource for the current month. Limits are set in the Level2 system. | + | ---------------------------- HELPERS --------------------------- |
- | Possible resources names are: " | + | -- invokes all functions related to weather |
+ | function weatherDemoLevel2() | ||
- | Data is taken from Level2. Data on WebHMI is usually updated no later than 1 hour after they are updated | + | local wdata = GetCurrentWeather() |
+ | tprint(wdata) | ||
+ | --[[ | ||
+ | The GetCurrentWeather function returns the current weather conditions at the WebHMI | ||
+ | The data is being updated | ||
+ | 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 service requires an Internet connection, an account in Level2. The function is available since version 2.9. | + | 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. | ||
+ | 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(" | ||
+ | --[[ 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(" | ||
+ | --[[ 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. | ||
+ | --]] | ||
- | If for some reason the data has not been received, the value nil will be returned. | + | end |
- | ==== GetTodayDayType() ==== | + | -- prints a table |
+ | function tprint(t, indent) | ||
+ | if not indent then indent | ||
+ | for k, v in pairs(t) do | ||
+ | local formatting | ||
+ | if type(v) | ||
+ | ERROR(formatting) | ||
+ | tprint(v, indent + 1) -- recursive call | ||
+ | else | ||
+ | if type(v) == " | ||
+ | v = v and " | ||
+ | end | ||
+ | ERROR(formatting .. v) | ||
+ | end | ||
+ | end | ||
+ | end | ||
- | The GetTodayDayType function returns the type of the current day: work, holiday, holiday. The types of days are set in the Level2 system. | ||
- | Three types are valid: " | ||
- | Data is taken from Level2. Data on WebHMI is usually updated no later than 1 hour after they are updated in Level2. If there is no connection, the system will return the limits from the cache. The cache stores the limits for the current and the next two months. | ||
- | |||
- | The service requires an Internet connection, an account in Level2. The function is available since version 2.9. | ||
- | |||
- | If for some reason the data has not been received, the value nil will be returned. | ||
- | ==== GetTomorrowDayType() ==== | + | </ |
- | + | ||
- | The GetTomorrowDayType function is completely analogous to GetTodayDayType with the only difference that it returns data about the future. | + | |
- | + | ||
- | ==== GetHolidaysStats() ==== | + | |
- | + | ||
- | GetHolidaysStats returns a table with the following fields: | + | |
- | + | ||
- | ***currentMonthDays** – number of days in the current month | + | |
- | ***nextMonthDays** - number of days in the next month | + | |
- | ***currentMonthWeekends** - the number of dayoffs (according to the settings in the Level2 system) in the current month | + | |
- | ***nextMonthWeekends** - the number of dayoffs (according to the settings in the Level2 system) in the next month | + | |
- | ***currentMonthHolidays** - number of holidays (according to the settings in the Level2 system) in the current month | + | |
- | ***nextMonthHolidays** - number of holidays (according to the settings in the Level2 system) in the next month | + | |
- | + | ||
- | Data is taken from Level2. Data on WebHMI is usually updated no later than 1 hour after they are updated in Level2. If there is no connection, the system will return the limits from the cache. The cache stores the limits for the current and the next two months. | + | |
- | + | ||
- | The service requires an Internet connection, an account in Level2. The function is available since version 2.9. | + | |
- | + | ||
- | If for some reason the data has not been received, the value nil will be returned. | + | |
get_weather_conditions_and_forecast.1547030058.txt.gz · Last modified: 2019/01/09 10:34 by akuzmuk