Logic Machine Forum
Trends API - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: Trends API (/showthread.php?tid=313)

Pages: 1 2


RE: Trends API - Trond Hoyem - 17.06.2022

(17.06.2022, 13:23)admin Wrote: Not 120 but 127.0.0.1

You are right. The typo is only in the previous post, the address in the script is 127.0.0.1.


RE: Trends API - admin - 17.06.2022

The error comes from having @ symbol in the password. It confuses the URL parser. Try using a password without @.


RE: Trends API - Trond Hoyem - 17.06.2022

(17.06.2022, 13:30)admin Wrote: The error comes from having @ symbol in the password. It confuses the URL parser. Try using a password without @.

Yes, I saw that as well, so I have changed the password so that there is no @ any more. 

I now get "timeout" in stead of "host not found"


RE: Trends API - admin - 17.06.2022

The IP blocker might have blocked local access because of wrong password. Reboot the device and try again.


RE: Trends API - Trond Hoyem - 17.06.2022

(17.06.2022, 13:34)admin Wrote: The IP blocker might have blocked local access because of wrong password. Reboot the device and try again.

I have also tried that. I actually down-powered it and repowered. Still same timeout.


RE: Trends API - admin - 17.06.2022

What do you get logged from this script?
Code:
require('socket.http')
log(socket.http.request('http://127.0.0.1/'))



RE: Trends API - Trond Hoyem - 17.06.2022

(17.06.2022, 14:15)admin Wrote: What do you get logged from this script?
Code:
require('socket.http')
log(socket.http.request('http://127.0.0.1/'))

Here is the whole script: 
Code:
require('json')
require('socket.url')
require('socket.http')

user = 'admin'
Password = 'Ringshusveien_18'
tag = 'nyTrend'

-- 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


obj = grp.tag(tag)


for _, addr in ipairs(obj) do

  object = addr.address
  alias = addr.name

  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)
  grp.removetags(addr.name, tag)

  res, err = socket.http.request('http://' .. user .. ':' .. password .. '@127.0.0.1/scada-main/trends/save', post)
  log(res, err)

end


script.disable(_SCRIPTNAME)


I am basically logging the result and errors from the saving of the trend.


RE: Trends API - admin - 17.06.2022

Works for me. Try running script from my previous post and see what you get in Logs.
Your script is also missing trend_type variable. It should be either 'C', 'D' or 'G' (counter, counter with negative delta or absolute value respectively).