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

Question

Posted

Hello everyone.

I 'm trying to build my own html site as front end.

But i can't seem to figuer out how to get the json data back from the api into html

Things like :

http:///api/weather?callback=?

and

http:///api/rooms

i've tryed thingslike :

$.getJSON("http:///api/weather?callback=?", function(data) {

// Get the element with id summary and set the inner text to the result.

$('#summary').text(data.result);

});

but what ever i'm trying i dont get any data back. Only when i put the url directly into the browers. so the HCL is giving me the data but i cant get them into my HTML code

Does any of you have a working sample ?

6 answers to this question

Recommended Posts

  • 0
Posted

Have a look at what I've done:

Please login or register to see this link.

Look at the "infosprite.php" this is doing what you want to. Basically, you import the entire file content of the api output you are trying to decode (through "file_get_contents"), then decode the json into a multidimensional array with the nifty built in decoder that php comes with. Then I just reload the php script every second in a hidden div where I can fetch the data from.

  • 0
  • Inquirer
  • Posted

    Thanks for the input. I take a look at it.

    I was working with the Jqeurry's but no luck so far.

    i was hoping to get everything into simple html files, no php, asp.

    So i can run the files directly from a tablet, pc,... without a webserver.

    • 0
    Posted

    It sounds like you just want to extract the data once. If that's the case, you can paste the URL into json-csv.com and extract the data into a spreadsheet. Then you can save it as HTML from there.

    • 0
    Posted

    Looking at the above code, you seem to be missing the authentification. So basically, you are trying to get data out without credentials. So first step is to get the json by providing the hc with your credentials, then the next step will be to convert that response into something useful. I don't know how/if jQuery will handle basic authentification though.

    • 0
    Posted

    Hi, I thing you problem is

    Please login or register to see this link.

    .

    You can't get data from the API using jQuery if the script is running from an other domain.

    This is only possible if you use JSONP, the problem with JSONP is that the server side must support this and HC2 dosen't support JOSNP callbacks. So you have to use a proxy service to get it to work unfortunately.

    I was writing a Pebble app when I realsed this problem.

    • 0
    Posted

    I think a proxy is adviceable anyway. Especially if you expect to have several devices polling the HC2 simultaneously (in my setup I have 7 tablets requesting updates every second, plus any commands sent back to the HC) it is probably a good idea to only have one device polling the HC2 and then all the other devices polling the Proxy, as this will be much better suited to handle the high number of requests being received from all your devices. I haven't personally had latency issues with the HC2, but other people are reporting that when they try to poll it often, it will start to lack as it apparantly has a hard time coping with many requests (especially if they arrive simulaneously I gather).

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