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


Recommended Posts

Posted

Hi all,

 

I managed to do a HTTP Post request with the following LUA code in a scene:

 

Please login or register to see this code.


Now I want to transfer this code to a virtual device and came to know that the net.HTTPClient() function is not working in a virtual device. It seems that one needs to use net.FHttp() function. However, I was not able to get it running and did not find any API documentation as well. Anybody who can help to get a HTTP Post request running in a virtual device (including header and body). Thanks in advance!

Posted (edited)

..

Edited by ToniK
Posted

Hi @ronaldQ ,

 

before we go further I need to mention that HC2 virtual devices HTTP is very basic and does not support TLS protection and either HTTPS.

If it is device on the local network then following code could work:

Please login or register to see this code.

Notice that to initialize HTTP you will need device IP address and TCP port. Also, You will need to play with code line 7 where basic authorization is added to the headers. I didn't check, but you can try if httpc:setAuthorization(api_key) will work. I added debug lines that should tell you what is received and using that you can adjust some code to make it work.

BTW - this code is modified from code that I use to control LaMetric smart clock.

 

If call is to the device cloud or to some internet service that still use unsafe HTTP instead of HTTPS then above code needs to be changed and instead of IP address and TCP port you need to use DNS name of the cloud service, e.g. "forum.fibaro.com" or "api.waqi.info" to initialize HTTP.

 

Hope this helps.

 

Join the conversation

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

Guest
Reply to this topic...

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