Compare commits
No commits in common. "83c395dcce2c796b821fc53fcab7fef4c5b76af9" and "93b789d4819975d3ed3a0b242b8e606efcee0636" have entirely different histories.
83c395dcce
...
93b789d481
|
@ -1,2 +0,0 @@
|
|||
node_modules
|
||||
npm-debug.log
|
17
Dockerfile
17
Dockerfile
|
@ -1,17 +0,0 @@
|
|||
FROM node:16
|
||||
|
||||
# Create app directory
|
||||
WORKDIR /usr/src/app
|
||||
|
||||
# Install app dependencies
|
||||
# A wildcard is used to ensure both package.json AND package-lock.json are copied
|
||||
# where available (npm@5+)
|
||||
COPY package*.json ./
|
||||
|
||||
RUN npm install
|
||||
|
||||
COPY . .
|
||||
|
||||
EXPOSE 9911
|
||||
|
||||
CMD [ "node", "raumstatus.js" ]
|
17
README.md
17
README.md
|
@ -31,20 +31,3 @@ Das meiste an Funktionn wurde wiede raus geworfen weil sich die CTDO infrastrukt
|
|||
sehr verändert hat und einiges kaputt war.
|
||||
|
||||
Der Status zeit nur noch Power und Raumstatus an. Es läuft wie gehabt via nmap-Ping.
|
||||
|
||||
|
||||
|
||||
## Dev hinweise
|
||||
|
||||
Man braucht dieses repo, nodejs ~16 mit npm.
|
||||
|
||||
|
||||
Dependencies installieren und Server lokal laufen lassen:
|
||||
|
||||
npm install
|
||||
node raumstatus.js
|
||||
|
||||
|
||||
Docker container bauen:
|
||||
|
||||
docker build . -t ctdo/ctdo-raumstatus
|
31
ip-poll.js
31
ip-poll.js
|
@ -3,32 +3,23 @@ var EventEmitter = require('events').EventEmitter;
|
|||
var exec = require('child_process').exec;
|
||||
|
||||
|
||||
var IpPoll = function(target) {
|
||||
var IpPoll = function(switchaddr, hostsaddr) {
|
||||
var self = this;
|
||||
|
||||
var regexp = /([0-9]+)% packet loss/m;
|
||||
var command = "LANG=C ping -c 2";
|
||||
var regexp = /\(([0-9]+) hosts* up\)/;
|
||||
var nmap = "nmap -n -sP ";
|
||||
|
||||
this.pollState = function() {
|
||||
try {
|
||||
exec(command + " " + target, function (error, stdout, stderr) {
|
||||
// console.log(stdout);
|
||||
|
||||
exec(nmap + switchaddr, function (error, stdout, stderr) {
|
||||
if(error == null) {
|
||||
var matches = regexp.exec(stdout);
|
||||
if (matches != null) {
|
||||
|
||||
// console.log("matches " + JSON.stringify(matches));
|
||||
// console.log("length: " + matches.length);
|
||||
// console.log("matches 1: " + matches[1]);
|
||||
|
||||
if (matches.length === 2) {
|
||||
self.emit('doneState', matches[1] === "0");
|
||||
}
|
||||
if(matches != null && matches.length === 2) {
|
||||
self.emit('doneState', matches[1] === "1");
|
||||
}
|
||||
});
|
||||
} catch(err) {
|
||||
self.emit('doneState', "unknown");
|
||||
}
|
||||
} else {
|
||||
self.emit('doneState', "unknown");
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
};
|
||||
|
|
|
@ -68,9 +68,8 @@ var flukso = new Flukso("flukso.raum.ctdo.de", "/sensor/cf00e0b22230f4a8870af58f
|
|||
var mqtt = mqttClient.connect('mqtt://raum.ctdo.de');
|
||||
var connected = false;
|
||||
|
||||
//express js settings
|
||||
var port = '9911';
|
||||
var address = '0.0.0.0';
|
||||
var address = 'localhost';
|
||||
|
||||
|
||||
ippoll.on('doneState', function (state) {
|
||||
|
|
|
@ -5,7 +5,7 @@ block content
|
|||
.intro
|
||||
p
|
||||
| Hier siehst du den aktuellen Status von uns. Die Daten werden vom Router und unserem Flukso
|
||||
| eingesammelt. Der Status selber werden Minütlich abgefragt. Unseren
|
||||
| eingesammelt. Die Anzahl der Geräte und der Status selber werden Minütlich abgefragt. Unseren
|
||||
| Energieverbrauch bekommst du alle fünf Sekunden neu. Den Status "geöffnet" oder "geschlossen"
|
||||
| bestimmt das Programm mit einem ping auf ein Gerät im Raum.
|
||||
|
||||
|
|
Loading…
Reference in New Issue