Your Universal Remote Control Center
RemoteCentral.com
Philips Pronto Professional Forum - View Post
Up level
Up level
The following page was printed from RemoteCentral.com:

Login:
Pass:
 
 

Original thread:
Post 6 made on Saturday March 9, 2024 at 07:25
sebastian
Long Time Member
Joined:
Posts:
September 2003
93
I agree with Lyndel, use the HTTP library.
Depending on the kind of "post-processing" you're planning to do, adding a JSON library might be a lot of overhead.

If you only need a few single values, you can try to grab those with a regular expression.

E.g., this is how I grab the state of my Hue lights from my home automation system (Home-Assistant). It should work similar when talking to the Hue bridge directly:

var request = [];
function getState(entityId) {
    request[entityId] = new com.philips.HttpLibrary.HttpRequest();
    request[entityId].open("GET", "http://" + ha_host + ":" + ha_port + "/api/states/" + entityId, true);
    request[entityId].setRequestHeader("Authorization:", "Bearer " + ha_token);
    request[entityId].setRequestHeader("Content-Type:", "application/json");

    var state;
    request[entityId].onreadystatechange = function() {
        if (request[entityId].readyState == 4) {

            regex = /"state": "(\w+)"/;
            state = (request[entityId].responseText).match(regex)[1];
            if (state == "on") {
                CF.widget(entityId).setImage(IMG_ON);
                CF.widget(entityId).label = "on";
            } else {
                CF.widget(entityId).setImage(IMG_OFF);
                CF.widget(entityId).label = "off";
            }
        }
    }
    request[entityId].send();
};


Sebastian


Hosting Services by ipHouse