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

I needs HTTPS support - Net.FHttps ?


Question

Posted

Hi Fibaro team,

I needs Https post

Please login or register to see this image.

/emoticons/default_icon_curve.gif" alt=":-/" /> Is this possible and how to do this ?

Best regards.

[ Added: 2013-05-06, 21:01 ]

there is nobody here

Please login or register to see this image.

/emoticons/default_icon_mrgreen.gif" alt=":mrgreen:" />

Recommended Posts

  • 0
Posted

local httpClient = net.HTTPClient();

httpClient:request("

Please login or register to see this link.

{
success = function(resp)
print("Status = " .. resp.status)

 

I am testing HTTPS using the link above, but what means the STATUS CODES I got?

Tested and got "Status = 200" which means connection OK I suppose.

 

With different settings I can got code 201 or 400.

What means the code 201 and code 400?

  • 0
Posted

Please login or register to see this link.

  • 0
Posted

Thank you Petergebruers, I thougth it was special Fibaro codes

Please login or register to see this image.

/emoticons/default_icon_redface.gif" alt=":oops:" />

  • 0
Posted

No problem

Please login or register to see this image.

/emoticons/default_icon_wink.gif" alt=";-)" />

Happy hacking!

  • 0
Posted

Hi,

 

Is there any way to post HTTPS requests in a Virtual Device?

I know you can do it in a scene using net.HTTPClient, but there are other things you can't do in a scene (like open a socket) that you can only do in a virtual device.

 

Why is there so much difference between the Lua in Scenes and the Lua in Virtual Devices?

 

It seems everyone was very vocal about needing this feature.  Then it was half given when v4 came around.  Now nothing....

 

The original request was for Net.FHttps to work alongside Net.FHttp   

 

Fibaro: will this ever be done?

  • 0
Posted

Argh!

 

Even net.HTTPClient is unusable!

 

The picture this morning:

 

I have a Virtual Device that makes HTTP requests and looks at the content of the responses.  Based on these, it sends out some other HTTP requests to other places.  I have been doing this successfully with Net.FHttp.  This code then loops and checks for a change by repeating first request.

 

I now need to send HTTPS requests for the second part.  But there is no way of doing this in a VD.

 

After writing the above post:

 

Thinking about it, I decided that as I'm only making HTTP REST requests, I don't actually need to be in a VD, as (apparently) I can use net.HTTPClient in a scene to do this.

 

So, i copied over my code and then started stripping it of VD related stuff I didn't need (like getSelfId, etc).

 

I then discovered that net.HTTPClient uses a callback as it works "synchronously" with the main code.

 

That's ok, I thought, I'll just set a flag that tells the main code to pause until the HTTPClient calls one of the callback functions (success or error).

 

BUT I didn't even get that far...  it turns out that net.HTTPClient doesn't trigger the callback functions until after the main program has finished running!

 

As my code is in a loop (because I need to keep polling these requests), the main code never finishes!  As a result the callbacks never come!  (To be 100% honest, I don't know if it is the callbacks that don't get called, or if the request is even sent before the main code finishes.)

 

 

WHAT KIND OF SYNCHRONOUS CODE IS THAT?!   It should be EITHER blocking (waits for a reply before continuing), or non-blocking (gets on and does its stuff no matter what the parent task is doing), but not this hybrid, uselessness!  Why Fibaro?!  Why?

 

Could someone with a little more experience with this please shed some light on this?

 

My next port of call is to try and get it working by using multithreading, but I'm not sure I really want to take it that far - especially for an ASynchronous procedure!

 

heatWave

 

PS.  This could all be fixed Fibaro, if you just implemented Net.Https in virtual devices.  Or EVEN BETTER implemented them BOTH in the scenes engine too!

  • 0
Posted

Stay calm and keep breathing

Please login or register to see this image.

/emoticons/default_icon_smile.gif" alt=":-)" />

You can "loop" with HTTPClient. It's a bit like a recursive call. The last thing you do in main is setup the call. It will execute immediately, because main ends, and then the call is made, as you found out yourself. When the answer arrives, your callback runs. At the end of the callback, simply schedule a new call. As soon as you callback ends, the next http call is made. You can pass parameters to keep track of things.

One way of doing it, is wrapping your code in a function, like this:

 

Please login or register to see this code.

The processing of the data is done by calling "process(response,deviceID)"

Is long as the current ID is lower than gloable endID, after processing, the next device ID is "called" by doing "analyze(deviceID+1)"

I'm sorry, but the code is not runnable because it is a snippet from a very large script.

EDIT: You start the loop by doing "analyze(startID)" at the end of the script.

  • 0
Posted

Somewhat related is this script. It's runnable code. Can you explain the result(s) - if you run it a few times?

 

Please login or register to see this code.

  • 0
Posted

Hi,

 

Thanks for your responses!

 

So can I confirm then, any variables that are accessible in the scope where http:request() is called, will be available to the success and error closures within it?

Does this mean that this will work:

Please login or register to see this code.

Will this output the following?  Message: Hello world

 

Can I use the http variable again within the closure or do I need to create a new one?

 

 

Thanks for your advice to keep breathing 

Please login or register to see this image.

/emoticons/default_icon_smile.gif" alt=":-)" /> it worked.

 

Regarding your second reply, I assume that the delay in the response from google as opposed to the local responses from the HC2 are what cause that to come in last all the time.

  • 0
Posted

Yes, yes, yes!

Please login or register to see this image.

/emoticons/default_icon_wink.gif" alt=";-)" />

Good example. I've modified it slightly to use the data from the HC2, and to demonstrate the recursive calling (runnable code):

 

Please login or register to see this code.

  • 0
Posted

Thanks petergebruers,

 

That has helped a lot.

  • 0
Posted

Hi,

 

Ok, so the Lua code seems to be working now - to a point.  I can use the

Please login or register to see this link.

URL with no problems.  It works and I get a 200 response as expected.

 

However, if I try my HTTPS URL (an AWS API Gateway GET), I get the following error returned:

Please login or register to see this code.

My thoughts:

1)  I can manually paste my URL into a browser and it works - multiple times.  So I know it's not the URL.

2)  The Lua code works fine with the google HTTPS site.  So I know it's not the script, or HTTPS not working.

3)  The error implies that a TCP socket has not been closed and is trying to be used again.  

 

My conclusion:  Fibaro have not implimented the net.HTTPClient correctly, and it only works on some resources.

 

 

Has anyone come across this error before? 

 

Thanks

  • 0
Posted

Do I understand it right that you cannot make code like this:

Please login or register to see this code.

Is it any chance to do such code in Scene using net.HttpClient()

  • 0
Posted

Do I understand it right that you cannot make code like this:

(...)

Indeed, that code won't work. But there is no need to write it that way. Please have a look at post #31. See where it says: "-- Run it a second time"? The scene will be at that point, after the response from Google got in. If your code could work (It can't) then you would be at this line: "if WaitPlease == false then", right after the callback. Those two lines of code would be executed at the same time, so to speak. But what to do you want to do next? You have no code after this, the script ends. Suppose, maybe, you want to switch on a light? In that case, replace "-- Run it a second time" and the following lines with "the code to switch on the light". You don't have to use recursion, as I do in my example. It could end all there. You can call another function. You can do another request (any request!).

The general pattern is like this (see post #35)

- Write the code to process an answer.

- Put that code in a function wrapper, and hand it over to http:request

- Do the request and let the main code of your scene finish

The code (in the function wrapper) will run, when there's data to process. So this mechanism never uses polling ("while x ~= y do end") do block the code until an answer arrives.

In the "code to process and answer" an answer, you decide what to do next. Maybe you want to loop this forever? That's possible. Right before the "end" of the block with all the processing, do the same http:request with the same function (same code). You want to call another URL with other code? Construct a request. You kind of daisy chain the call-response sequences together.

Remember to pass data to the next function, if you need this (or indirectly use variables captured by the closure, like "message" in the example).

The code to do HTTP in a VD is "blocking" so if you find it easier to write it that way, it's possible in a VD.

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