Antwort
Jun 01, 2020 - 10:59
Hallo,
bin das Thema neu angegangen. Statt ein CCU Skript zu portieren einfach neu entwickelt. Hier mal die erste Version:
ciao Walter
bin das Thema neu angegangen. Statt ein CCU Skript zu portieren einfach neu entwickelt. Hier mal die erste Version:
//
//
url = "http://htmluser:sassicaja@192.168.178.205:8181/egal.exe?x=dom.GetObject(ID_DEV
ICES).EnumUsedIDs()";
// url = "http://htmluser:sassicaja@192.168.178.205:8181/egal.exe?x=dom.GetObject(ID_CHA
NNELS).EnumUsedIDs()";
// var url = "http://htmluser:sassicaja@192.168.178.205:8181/egal.exe?x=dom.GetObject(ID_DAT
APOINTS).EnumUsedIDs()";
//
var dpid;
const BidCosLOWBAT = ["HM-Sec-SCo", "HM-Sec-RHS", "HM-Sec-RHS-2", "HM-Sec-SD-2"];
const BidCosBatState = ["HM-CC-RT-DN", "HM-RC-Dis-H-x-EU"];
const BidCosNoBat = ["HM-PB-2-WM55", "HM-PB-2-WM55-2", "HM-RC-Dis-H-x-EU"];
//
// function for id numbers
//
const getObj = function(objurl) {
// return new pending promise
return new Promise((resolve, reject) => {
// select http or https module, depending on reqested url
const lib = url.startsWith('https') ? require('https') : require('http');
// const lib = require('http');
const request = lib.get(objurl, (response) => {
// handle http errors
if (response.statusCode < 200 || response.statusCode > 299) {
reject(new Error('Failed to load page, status code: ' + response.statusCode));
}
// temporary data holder
const body = [];
// on every content chunk, push it to the data array
response.on('data', (chunk) => {
body.push(chunk);
});
// we are done, resolve promise with those joined chunks
response.on('end', () => {
resolve(body.join(''));
});
// handle connection errors of the request
request.on('error', (err) => reject(err));
});
});
};
//
// main call
//
getObj(url)
.then((devids) => {
devids = devids.match(/[0-9]+/g);
// console.log(devids + "\n\r");
devids.forEach(devid => {
// get device name
getObj("http://htmluser:sassicaja@192.168.178.205:8181/egal.exe?x=dom.GetObject
(" + devid + ").Name()")
.then((devname) => {
// console.log(devname + "\n\r");
devname = devname.match(/([(A-Z)(a-z)(0-9)(_-\s.)]*?\b)(?=<\/x>)/g);
if (devname !== null) {
// console.log(devname + "\n\r");
getObj("http://htmluser:sassicaja@192.168.178.205:8181/egal.exe?x=dom.GetObject
(" + devid + ").Channels()")
.then((chnids) => {
chnids = chnids.match(/[0-9]+/g);
// get channel ids
if (chnids !== null) {
// console.log(chnids + "\n\r");
chnids.forEach(chnid => {
// get data point ids
getObj("http://htmluser:sassicaja@192.168.178.205:8181/egal.exe?x=dom.GetObject
(" + chnid + ").DPs()")
.then((dpids) => {
dpids = dpids.match(/[0-9]+/g);
if (dpids !== null) {
// console.log(dpids + "\n\r");
dpids.forEach(dpid => {
getObj("http://htmluser:sassicaja@192.168.178.205:8181/egal.exe?x=dom.GetObject
(" + dpid + ").Name()")
.then((dpname) => {
// console.log(dpname);
dpname = dpname.match(/([(A-Z)(a-z)(0-9)(_-\s)]*?\b)(?=<\/x>)/g);
// console.log(dpname[0]);
if (dpname !== null && (dpname[0] == "LOWBAT" || dpname[0] == "LOW_BAT" || dpname[0] == "BATTERY_STATE")) {
// console.log(dpname);
getObj("http://htmluser:sassicaja@192.168.178.205:8181/egal.exe?x=dom.GetObject
(" + dpid + ").Value()")
.then((dpvalue) => {
dpvalue = dpvalue.match(/([(A-Z)(a-z)(0-9)(_-\s.)]*?\b)(?=<\/x>)/g);
// console.log("Device: " + devname + " devID: " + devid + " Value: " + dpvalue);
if (dpvalue || dpvalue <= 2.2) {
console.log(devname + ": Battery ok. - " + dpvalue);
} else if (!dpvalue || dpvalue > 2.2) {
console.log(devname + ": Change Battery. - " + dpvalue)
}
});
}
});
});
}
})
.catch((err) => console.log(err));
});
}
})
.catch((err) => console.log(err));
}
});
});
})
.catch((err) => console.log(err));
ciao Walter
Neuen Kommentar hinzufügen