This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

How create scripts and trends by script ?
#1
Hello,

I would like to make a script that creates a new trend and a new script automatically on an event.

Is there some solution with LM functions or lua to make this ?
Reply
#2
Right now there's no Lua API for creating scripts and trends. Can you describe what kind of task do you have which requires this functionality?
Reply
#3
(19.11.2015, 07:25)admin Wrote: Right now there's no Lua API for creating scripts and trends. Can you describe what kind of task do you have which requires this functionality?

I would like to be able to select some move sensor in user interface. If a sensor is selected, a script create :
> an event script that sum move's events of the sensor
> a trend to give an historic of the activity 

I was thinking about calling the function that create the trend / script in LM interface but call it by script. But I don't know if it could be called by lua.
Reply
#4
I suggest using a single script attached to object tag, this way you can dynamically add/remove objects. See this doc: http://openrb.com/docs/lua.htm#grp.addtags

You can use LuaSocket http request to create new trend by sending a POST request. I'll provide an example later.
Reply
#5
(19.11.2015, 13:36)admin Wrote: I suggest using a single script attached to object tag, this way you can dynamically add/remove objects. See this doc: http://openrb.com/docs/lua.htm#grp.addtags

You can use LuaSocket http request to create new trend by sending a POST request. I'll provide an example later.

Thank you for your answer, I think I will use the POST request solution.
Reply
#6
Here's an example for creating trends, don't forget to set admin password in socket.http.request:


Code:
require('json')
require('socket.url')
require('socket.http')

object = '1/1/1'

trend = {
 object = knxlib.encodega(object),
 name = 'New trend', -- trend name
 type = 'C', -- C is counter, D is counter with neg. delta, G is absolute value
 precision = 2, -- floating point precision
 count_minutely = 24 * 60, -- 1 day
 count_hourly = 24 * 365, -- 1 year
 count_daily = 365, -- 1 year
}

data = json.encode(trend)
post = 'data=' .. socket.url.escape(data)

res, err = socket.http.request('http://admin:admin@127.0.0.1/cgi-bin/scada/general/request.cgi?_module=trends&_action=save', post)
log(res, err)
Reply
#7
It works fine, Thank you
Reply
#8
How to change it to other values? I want create trend with below parameters:
Trend resolution: 5 minutes
Resolution data: 1 year
Daily data: 2 years

This is the part of my script which has error 302:

Code:
trend = {
     object = knxlib.encodega(object), -- object id in db
     name = alias, -- trend name
     type = 'G',
     precision = 2,
     count_minutely = 365*24*60,
     count_hourly = 2*24*365,
     count_daily = 5*365
   }

And this is what I've logged by log(trend, res, err):

Code:
* arg: 1
 * table:
  [object]
   * number: 66048
  [count_daily]
   * number: 1825
  [count_minutely]
   * number: 525600
  [type]
   * string: G
  [precision]
   * number: 2
  [name]
   * string: PEGO_Goscinna - Room humidity
  [count_hourly]
   * number: 17520
* arg: 2
 * string: <html>
<head><title>302 Found</title></head>
<body bgcolor="white">
<center><h1>302 Found</h1></center>
<hr><center>nginx</center>
</body>
</html>

* arg: 3
 * number: 302
OK, I've found that this is from not current firmware. I've found how to do this in current firmware:
Code:
require('json')
require('socket.url')
require('socket.http')

-- parameters
daily = 365*24*60 -- 1 day
daily1year = 365*24*12 -- 365 day
daily2year = 2*365*24*12 -- 365 day
year5_d = 5*365 -- 5 year

object = grp.alias('Kitchen_Temperature')
   
trend = {
 object = knxlib.encodega(object), -- object id in db
 name = alias, -- trend name
 type = trend_type,
 resolution = 5, -- every 5 minute
 precision = 2, -- floating point precision
 count_resolution = 365*24*12, -- 1 year
 count_daily = 5*365 -- 5 years
}

data = json.encode(trend)
post = 'data=' .. socket.url.escape(data)
        
res, err = socket.http.request('http://admin:admin@127.0.0.1/scada-main/trends/save', post)
log(res, err)
Done is better than perfect
Reply
#9
First 6 trends are successfully created but another not and there is such res:

Code:
* arg: 2
 * string: {"size":true,"success":false}
* arg: 3
 * number: 200


What means "size": true? I have enought space on LM and also RAM is ~50%.

I've tried also to add trend via Editor and there is such error. I didn't know that there is a limit in trends? I have only 24 trends on this LM.

Attached Files Thumbnail(s)
   
Done is better than perfect
Reply
#10
Hi
Trends do have a limit to make sure you will not eat whole ram. It is around 30MB or something like that. Use lower resolution or shorter period.
BR
------------------------------
Ctrl+F5
Reply
#11
But it is variable because on LM-LB it is ~limitless and I also remember another LM4 and probably I had there much more than here.

What is the limit or dependancy(e.g. 50% of RAM)? I will consider it on planningWink
Done is better than perfect
Reply
#12
This limit was implemented in latest fw I think. In the past there was no limit and we had cases when whole ram was used and device was rebooting all the times. It is around 30MB.
------------------------------
Ctrl+F5
Reply
#13
(28.02.2018, 12:03)Daniel. Wrote: This limit was implemented in latest fw I think. In the past there was no limit and we had cases when whole ram was used and device was rebooting all the times.  It is around 30MB.

But this is same on every LM or e.g. power version and Load Balancer has more. Could you check this?

I understand that there was such need.
Done is better than perfect
Reply
#14
All devices have the same CPU now, in other words all of them are power now. Old and new devices have the same firmware.
We phased out LM BL and you can't buy it anymore. We can generate new fw for them on request.
In some time from now we will have new HW with even faster CPU and double the RAM. This will be nearly the same as LM BL. We could increase limit for trends then.
------------------------------
Ctrl+F5
Reply


Forum Jump: