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} What is the correct format for HTTP:PUT method?


Question

Posted (edited)

Hi,

 

I tried this.

 

Please login or register to see this code.

it works with GET end empty payload. But when I switch GET with PUT and fill the payload I receive:

 

Please login or register to see this image.

/monthly_2020_02/image.png.dcf2d727ccea9ffd4f91da380069b938.png" />

 

the IP address is 192.168.1.101/write

 

What is the correct way to use PUT method?

Thanks!

 

--EDIT SOLUTION--

 

IThe correct format for sending PUT request is:

 

selfId = fibaro:getSelfId()
deviceIp = fibaro:get(selfId, "IPAddress")   -- VD ip address
devicePort = fibaro:get(selfId, "TCPPort") -- VD port for ip
TERMI = Net.FHttp(deviceIp, devicePort) -- object definition

payload = '{"INTERVAL":"true","iTemp":"'..iTemp..'","iDuration":"'..iDuration..'"}' -- whatever payload you need, in my case some JSON objects
response ,status, errorCode = TERMI:PUT('/write' , payload)  -- remember to include payload! :-)

 

Best regards!

 

 

 

 

 

 

 

Edited by PiotrP

4 answers to this question

Recommended Posts

  • 0
Posted (edited)

First of all by defining variable payload, It's just a variable in code and I don't see you're sending that....

Please login or register to see this code.

You need to include payload in your call, since I don't know the syntax of your URL I cannot suggest how to do it (may be like that)

Please login or register to see this code.

Could you please post the data which you receive using "GET" method? It might help to understand what the syntax.

 

Correct HTTP definition is

Please login or register to see this code.

Make sure your port variable devicePort is number.

 

On 2/6/2020 at 6:39 PM, PiotrP said:

the IP address is 192.168.1.101/write

What port number and where is it in your command line?

It should be more like

192.168.1.101:80/write

 

Edited by cag014
  • 0
Posted (edited)

By the way, it could be a good idea if you can share what kind of device you're trying communicate to?

Might be that someone at forum has same device and could share necessary information.

Edited by cag014
  • 0
  • Inquirer
  • Posted (edited)

    Hi cag014,

    Thanks for the interest.

    I build a thermostatic device and implemented API based on JSON. Everything works on port 80 (defined in VD parameters)

    The API was tested with curl, and works like a charm.

     

    In HC2 I managed to implement GET method. The code that works is this:

    Please login or register to see this code.

    it gives nice response:

    Please login or register to see this image.

    /monthly_2020_02/image.png.c152e23497b4c6e45b57b2c5f7cfbbaf.png" />

     

     

    With GET it is enough to send URL, but with PUT I need to sent that JSON payload.

     

    Edited by PiotrP
    • 0
    Posted

    Do you have an example of "PUT" method in curl?

    As I see it, you need to know how to transfer the payload to device, I mean what is the correct syntax.

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