Dieser Artikel zeigt einige Beispiele zur Verwendung der JS SDK.
var CLIENT_SECRET = "YOUR_SECRET";
var CLIENT_ID = "YOUR_CLIENT_ID";
var api = new LM_API("client_credentials",CLIENT_ID,CLIENT_SECRET);
api.authenticate().then(function(){
// alert("done");
},function(){
alert("Authentication failed");
});
// Load a defined measuerement point
api.loadObject("customkey/alias").then(function(entry){
entry = entry[0];
var el=$("<div/>");
var time = new Date().getTime();
el.css("height","200px");
$("body").append("<h2>"+entry.getTitle()+"</h2>");
$("body").append(el);
entry.createChart(el);
entry.loadData(time-(86400000*4),time,"PT1H").then(function(data){
console.debug("Data loaded:",data);
});
el.on("data",function(event,data){
console.debug("DATA LAODED",data);
});
setTimeout(function(){
entry.updateChart(time-(86400000*4),time,"PT1H");
}, 5000);
});
var CLIENT_SECRET = "50b5832ed589659d6c5b30287a92ffb9"; var CLIENT_ID = "api_2049f1f06b3"; var api = new LM_API("client_credentials",CLIENT_ID,CLIENT_SECRET); api.authenticate().then(function(){ // alert("done"); },function(){ alert("Authentication failed"); }); // Load Assets of 1. layer api.loadAssets().then(function(assets){ assets.forEach(function(asset) { $(".title").text(asset.getTitle()+" "+asset.getId()); $(".image").attr("src",asset.getImage()); }); console.log("RAW OBJECT",assets[0].raw); console.log("Infos ",assets[0].getChildrenInfo()); // Load Properties of 1. Asset assets[0].loadProperties().then(function(children){ $("body").append("<h2>Properties</h2>"); console.log("PROPERTIES",children); children.forEach(function(entry) { $("body").append("<span>"+entry.getTitle()+": "+entry.getValue()+"</span><br>") }); }); // Load Documents of 1. Asset assets[0].loadDocuments().then(function(children){ $("body").append("<h2>Documents</h2>"); console.log("Documents",children); children.forEach(function(entry) { $("body").append('<a href="'+entry.getFile()+'">'+entry.getTitle()+"</a><br>") }); }); // Load Measurement Points of 1. Asset assets[0].loadMeasurementPoints().then(function(children){ /*children[0].loadData().then(function(data){ console.log(data); });*/ children.forEach(function(entry) { var el=$("<div/>"); var time = new Date().getTime(); el.css("height","200px"); $("body").append("<h2>"+entry.getTitle()+"</h2>"); $("body").append(el); entry.createChart(el); entry.loadData(time-(86400000*4),time,"PT1H").then(function(data){ console.debug("Data loaded:",data); }); el.on("data",function(event,data){ console.debug("DATA LAODED",data); }); setTimeout(function(){ entry.updateChart(time-(86400000*4),time,"PT1H"); }, 5000); }); console.log(children); }); });