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.

special caracter incurve script creation
#1
Hi,
I have a script to create the curve easily.
It work perfect/

My problem is about password, if my customer use special caracter like @ it doesn't work.
I tried to replace with %40 ...
ASCII/UNICODE... @ %40 @ Alt 64

example:

password= xxxXxxx%40yyyYyy

without sucess.
Any help apreciated

Code:
----------------------------
-- creer la courbe
function createCurve(adresse, classement)

  if adresse then
    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
    trend_type = 'C' -- C is counter, D is counter with neg. delta, G is absolute value
   
    object = adresse

   
    if grp.find(adresse) then
     
      --separe nom du cpt pour mettre que le libelle dans nom des courbes
      nom_compteur=grp.alias(adresse)
      nom_compteur_split=string.split(nom_compteur,'-')
         
      -- si pas total, on separe
      if nom_compteur_split[4] then
        zone=string.gsub(nom_compteur_split[2],'CPTTD_','')
        nom_compteur=zone..'-'..nom_compteur_split[5]
      end
     
      trend = {
        object = knxlib.encodega(object), -- object id in db
        name = nom_compteur, -- trend name
        type = trend_type,
        resolution = 60, -- every 5 minute
        precision = 1, -- floating point precision
        count_resolution = 365*24*12, -- 1 year
        count_daily = 5*365, -- 5 years
        category = classement
      }

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

            --auth=require('mime').b64('admin:'..password)
     
      --res, err = socket.http.request('http://'..auth..'@127.0.0.1/scada-main/trends/save', post)
      res, err = socket.http.request('http://admin:'..password..'@127.0.0.1/scada-main/trends/save', post)
      sleep(1)
      if err then
        log(res, err)
      end
    end

  end 
end
---------------------------
-----------
FRANCE SMARTHOME & SMARTBUILDING INTEGRATION
SE ECO EXPERT
Reply
#2
With 2021 firmware you can do it like this. Passing body as a table will automatically encode it as needed and will set request method to POST.
Code:
res, err = socket.http.request({
  url = 'http://127.0.0.1/scada-main/trends/save',
  user = 'admin',
  password = 'admin_p@ssword',
  body = {
    data = json.encode(trend)
  }
})
Reply
#3
(03.12.2021, 16:09)admin Wrote: With 2021 firmware you can do it like this. Passing body as a table will automatically encode it as needed and will set request method to POST.
Code:
res, err = socket.http.request({
  url = 'http://127.0.0.1/scada-main/trends/save',
  user = 'admin',
  password = 'admin_p@ssword',
  body = {
    data = json.encode(trend)
  }
})

Heart 
thanks.
work on HL and SL ?
-----------
FRANCE SMARTHOME & SMARTBUILDING INTEGRATION
SE ECO EXPERT
Reply
#4
With latest firmware it should work
Reply
#5
(03.12.2021, 16:16)admin Wrote: With latest firmware it should work

is there new limitation with SL/HL latest firmware? https?

I v got error now

* arg: 1
  * string: <html>
<head><title>301 Moved Permanently</title></head>
<body bgcolor="white">
<center><h1>301 Moved Permanently</h1></center>
</body>
</html>

* arg: 2
  * number: 301


-------

EDIT I needed to put:

url = 'https://127.0.0.1/scada-main/trends/save'

now works
-----------
FRANCE SMARTHOME & SMARTBUILDING INTEGRATION
SE ECO EXPERT
Reply


Forum Jump: