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

Virtual Device - Post JSON


Question

Posted (edited)

Hi All

 

I have spent hours reading manuals and forum posts trying to work this out and I can not get my head around it and I just cant find the answer I am looking for.

 

I would like to setup a virtual device button to do the following:

 

Perform a HTTP POST to

 

http://192.168.1.5/SystemON

 

with the content 

 

{
"SystemON":"on"
}

 

If someone could help me out, that would be fantastic.

Edited by automyhome

8 answers to this question

Recommended Posts

  • 0
Posted (edited)

try this:

 

Please login or register to see this code.

 

Edited by Joep
  • 0
  • Inquirer
  • Posted

    Hi Joep @

     

    Appreciate the help, however I am getting the below error.

     

    Any ideas?

     

     

    [ERROR] 21:48:19: line 5: '}' expected near '

    • 0
    Posted

    I just typed this, I missed a comma,

    Change 

    Please login or register to see this code.

    to 

     

    Please login or register to see this code.

    • 0
  • Inquirer
  • Posted

    Thanks Joep, I have made the change but I am still getting this error

    [ERROR] 22:30:32: line 5: '}' expected near '

    not sure if this information helps, but when i use a rest client it works, here is the log from the rest client

     

    * Preparing request to http://192.168.1.5:80/SystemON
    * Using libcurl/7.51.0-DEV OpenSSL/1.0.2j zlib/1.2.8 libssh2/1.6.1_DEV
    * Enable automatic URL encoding
    * Enable SSL validation
    * Enable cookie sending with jar of 0 cookies
    * Hostname in DNS cache was stale, zapped
    *   Trying 192.168.1.5...
    * TCP_NODELAY set
    * Connected to 192.168.1.5 (192.168.1.5) port 80 (#30)
    > POST /SystemON HTTP/1.1
    > Host: 192.168.1.5
    > User-Agent: insomnia/5.16.6
    > Content-Type: application/json
    > Accept: */*
    > Content-Length: 20
    | {
    | "SystemON":"on"
    | }
    * upload completely sent off: 20 out of 20 bytes
    < HTTP/1.1 200 OK
    < Connection: close
    < Content-Type: application/json
    < Cache-Control: no-cache

    * Received 0 B chunk
    * Curl_http_done: called premature == 0
    * Closing connection 30

    • 0
    Posted (edited)

    Please login or register to see this code.

    Try this :)

    I don't know if it works, just a test because I have no access to my HC2.

    Edited by Joep
    • 0
  • Inquirer
  • Posted

    hmmm, that returns the following error.

     

     

    [ERROR] 23:02:12: line 1: attempt to index global 'net' (a nil value)

     

    as soon as i remove the ' that you have added, the error goes away and returns back to the original error. It must be something to do with the format of

    Please login or register to see this code.

     

    • 0
    Posted
    11 hours ago, automyhome said:

    hmmm, that returns the following error.

     

     

    [ERROR] 23:02:12: line 1: attempt to index global 'net' (a nil value)

     

    as soon as i remove the ' that you have added, the error goes away and returns back to the original error. It must be something to do with the format of

    Please login or register to see this code.

     

    I think net.HTTPClient() doesn't supported in virtual device. (Scenes only)

     

    • 0
  • Inquirer
  • Posted

    Thanks cag0114 and Joep for your help.

     

    I moved the code into a scene and made a few alterations and this is what has worked.

     

     

     

    local http = net.HTTPClient()

        http:request("http://192.168.1.5/SystemON", {

            options = { method = 'POST', headers = {}, data = '{"SystemON":"on"}', timeout = 2000 },

     }) 

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