Logic Machine Forum
special caracter incurve script creation - 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: special caracter incurve script creation (/showthread.php?tid=3728)



special caracter incurve script creation - domotiqa - 03.12.2021

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



RE: special caracter incurve script creation - admin - 03.12.2021

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



RE: special caracter incurve script creation - domotiqa - 03.12.2021

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


RE: special caracter incurve script creation - admin - 03.12.2021

With latest firmware it should work


RE: special caracter incurve script creation - domotiqa - 15.02.2023

(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