Access and parse the resource catalogue

Wikis > LinkSmart.net > IoTResource Catalogue > Access and parse the resource catalogue

First a short overview of the resource catalogue

Main page or root of the resource catalogue ex. http://hydra.cnet.se:44441/
RC_root

List of actions http://hydra.cnet.se:44441/services/catalogue/actions
RC_listActions

List of access resources http://hydra.cnet.se:44441/IoTresources
RC_resources

List of State variables http://hydra.cnet.se:44441/IoTresources/3/services/IoTObservation/statevariables
RC_services

Select a state variable and get latest 180 measurements http://hydra.cnet.se:44441/IoTresources/3/services/IoTObservation/statevariables/currentconsumption?take=180
RC_measurements

Read xml with Javascript


function readXml(url) {
var xhr = createCORSRequest('GET', url);
if (!xhr) {
console.log('CORS not supported');
return;
}

// Response handlers.
xhr.onload = function () {
var xml = xhr.responseText;
if (typeof firstAction !== ‘undefined’) {
console.log(xml);
}
};

xhr.onerror = function () {
console.log(‘Woops, there was an error making the request.’);
};

xhr.send();
}

function createCORSRequest(method, url) {
var xhr = new XMLHttpRequest();
if (“withCredentials” in xhr) {
// XHR for Chrome/Firefox/Opera/Safari.
xhr.open(method, url, true);
} else if (typeof XDomainRequest != “undefined”) {
// XDomainRequest for IE.
xhr = new XDomainRequest();
xhr.open(method, url);
} else {
// CORS not supported.
xhr = null;
}
return xhr;
}

 

Ex.
readXml('http://hydra.cnet.se:44441/services/catalogue/actions')