Jump to content

Welcome to Smart Home Forum by FIBARO

Dear Guest,

 

as you can notice parts of Smart Home Forum by FIBARO is not available for you. You have to register in order to view all content and post in our community. Don't worry! Registration is a simple free process that requires minimal information for you to sign up. Become a part of of Smart Home Forum by FIBARO by creating an account.

 

As a member you can:

  •     Start new topics and reply to others
  •     Follow topics and users to get email updates
  •     Get your own profile page and make new friends
  •     Send personal messages
  •     ... and learn a lot about our system!

 

Regards,

Smart Home Forum by FIBARO Team


  • 0

<solved> how to make HTTP request in VD


Question

Posted (edited)

hello,

i have following http request working in a scene but would like to transfer it to a VD but can't get it working.

 

jtable =('{"jsonrpc":"2.0","id":6538,"method":"read","params":{"objects":[{"id":"111","properties":{"85":{}}}]}}')

local http = net.HTTPClient()
local url=("http://192.168.0.34//api")
   http:request(url, {
    options={ 
      method = "POST";
      data = jtable
       },
    success = function(status)
      print("Success: "..status.status);
      if status.status == 200 then
        print(status.data);
      else
        print(status.status);
      end
    end
    })
  

 

I would also like to change the "id" in jtable for a local or global variable.

 

Hope someone can help me as i am stuck at this moment.

 

 

thanks

 

 

Edited by WimF

13 answers to this question

Recommended Posts

  • 0
Posted

Isn't POST a Scene only feature? I know there are some things you can do in Scene but not in VD.. dunno if there is a list of that somewhere..

  • 0
Posted
4 minutes ago, riemers said:

Isn't POST a Scene only feature? I know there are some things you can do in Scene but not in VD.. dunno if there is a list of that somewhere..

POST can be in VD either.

  • 0
Posted

What does it currently output? Does it error? Did you place some debug lines in there etc?

  • 0
  • Inquirer
  • Posted
    2 hours ago, riemers said:

    What does it currently output? Does it error? Did you place some debug lines in there etc?

     

    current failure is :

     

    [ERROR] 12:29:13: line 4: '' expected near '('

     
     
    and this does not give me any clue about what's going on.
    It must be something that doesn't work in a VD since this is running fine in a scene.
    • 0
    Posted

    Try adjusting: local url=("http://192.168.0.34//api")

    to local url="http://192.168.0.34//api"

     

    Atlhough it might work on the Scene, VD might not like that syntax.

    • 0
  • Inquirer
  • Posted
    24 minutes ago, riemers said:

    Try adjusting: local url=("http://192.168.0.34//api")

    to local url="http://192.168.0.34//api"

     

    Atlhough it might work on the Scene, VD might not like that syntax.

     

    @riemers thanks for your response.

     

    the change doesn't work in a VD ( same error). 

    Everything is running fine in a Scene as is but  i like to have this in a VD.

    • 0
    Posted

    VD should be Net.Fhttp()

     

    At least thats what

    Please login or register to see this link.

    • 0
  • Inquirer
  • Posted
    49 minutes ago, riemers said:

    VD should be Net.Fhttp()

     

    At least thats what

    Please login or register to see this link.

    Thanks,

     

    I tried that and the error is gone now, however the status reporting that the request was successful is now not working anymore.

    • 0
    Posted

    Try something like this:

     

    Please login or register to see this code.

     

    • 0
  • Inquirer
  • Posted
    56 minutes ago, boerremk said:

    Try something like this:

     

    Please login or register to see this code.

     

     

    @boerremk

     

    Thanks for your suggestion.

    unfortunately this does not work as well. 

    i get following error

     

    [ERROR] 21:53:33: line 3: attempt to index global 'net' (a nil value)

     
     
     
    • 0
    Posted

    I'm sorry... cut and paste error.... that line should be removed.

     

    Please login or register to see this code.

     

    • 0
  • Inquirer
  • Posted
    11 minutes ago, boerremk said:

    I'm sorry... cut and paste error.... that line should be removed.

     

    Please login or register to see this code.

     

    @boerremk

     

    Thanks again, 

    at least the error message is gone ,... but now nothing happen, no response at all.

    inserted debug line shows that it stops at line 1

    • 0
  • Inquirer
  • Posted (edited)
    21 hours ago, boerremk said:

    I'm sorry... cut and paste error.... that line should be removed.

     

    Please login or register to see this code.

     

    @boerremk

     

    found the problem.

    I was using some print statements to see what happened but when i changed the "print" for "fibaro:debug" this works fine and i get the expected result.

    Is "print" working in VD ??

     

     

    Edited by WimF

    Join the conversation

    You can post now and register later. If you have an account, sign in now to post with your account.

    Guest
    Answer this question...

    ×   Pasted as rich text.   Paste as plain text instead

      Only 75 emoji are allowed.

    ×   Your link has been automatically embedded.   Display as a link instead

    ×   Your previous content has been restored.   Clear editor

    ×   You cannot paste images directly. Upload or insert images from URL.

    ×
    ×
    • Create New...