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

How HTTP request in scenes with callback, get rooms for section?


Question

Posted (edited)

Hello guys,

please help me with asynchronous call with callback in http request in scenes.

I need write function with http request with return values from this function. same behavior I use in virtual devices.

 

But in scenes this function return nil.

How is possible use http request in scenes with callback.

thank you

Martin

 

easy function with select rooms for one section

 

Please login or register to see this code.

All debug texts in function works, but the function doesn't return anything.

Edited by marbe

4 answers to this question

Recommended Posts

  • 0
Posted

Does this one help? 

 

 

  • 0
  • Inquirer
  • Posted

    Hi,

    thank you for answer, but this works not, it ended with fatal error:

    [DEBUG] 18:27:40: 2018-12-13 18:27:40.244683 [ fatal] Unknown exception: /opt/fibaro/scenes/146.lua:10: attempt to index global 'Net' (a nil value)

     

    My code

    Please login or register to see this code.

     

    and this code doesn't return any data, its async function...

     

    Please login or register to see this code.

     

    • 0
    Posted
    On 12/13/2018 at 3:29 PM, marbe said:

    Hello guys,

    please help me with asynchronous call with callback in http request in scenes.

    I need write function with http request with return values from this function. same behavior I use in virtual devices.

     

    But in scenes this function return nil.

    How is possible use http request in scenes with callback.

    thank you

    Martin

     

    easy function with select rooms for one section

     

    Please login or register to see this code.

    All debug texts in function works, but the function doesn't return anything.

    Hello,

     

    The problem you have is that when you call 'getRoomsInSection' the function makes the HTTP call and then returns, it doesn't wait for the response from the HTTP call before returning so the returned value is Nil.

     

    You need to process the response from the network device in the callback.

     

    Ian

     

    • 0
    Posted
    On 12/13/2018 at 4:29 PM, marbe said:

    please help me with asynchronous call with callback in http request in scenes.

    If you are not used to writing code with "callbacks" then you will find it very difficult to write even the smallest program in that style...

     

    I can answer your question, see at the end of this post, but I'd like to offer an easier alternative: use(undocumented) blocking calls for HC2 API, like this:

     

    Please login or register to see this code.

     

    30 minutes ago, ianakapilotlight said:

    The problem you have is that when you call 'getRoomsInSection' the function makes the HTTP call and then returns, it doesn't wait for the response from the HTTP call before returning so the returned value is Nil.

     

    You need to process the response from the network device in the callback.

     

    Exactly. That indeed is the reason why the OP gets "nil" and I think this is what confuses many people.

     

    I introduced some concepts in this topic on "setTimeout" which is easier to work with but similar to "http client":

     

     

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