From d8e93ed5258595e4b0dc4dc74833fc4db8262bb1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucas=20Ple=C3=9F?= Date: Wed, 12 Oct 2022 08:48:30 +0200 Subject: [PATCH 1/2] feat: added environment variables for configuration --- raumstatus.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/raumstatus.js b/raumstatus.js index c9cdb37..a398e35 100644 --- a/raumstatus.js +++ b/raumstatus.js @@ -64,8 +64,9 @@ var simpleanswer = {state: "unknown", lastchange: 0, power: 0}; var ippoll = new IpPoll("rpi3.raum.ctdo.de"); -var flukso = new Flukso("flukso.raum.ctdo.de", "/sensor/cf00e0b22230f4a8870af58f2b8719dd"); -var mqtt = mqttClient.connect('mqtt://raum.ctdo.de'); +var flukso = new Flukso(process.env.FLUKSO_HOST || "flukso.raum.ctdo.de", + process.env.FLUKSO_URL || "/sensor/cf00e0b22230f4a8870af58f2b8719dd"); +var mqtt = mqttClient.connect(process.env.MQTT_SERVER || 'mqtt://mqtt.ctdo.de'); var connected = false; //express js settings -- 2.40.1 From 0082d4932b3b35011f0cc001cf34155acaf82812 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucas=20Ple=C3=9F?= Date: Tue, 18 Oct 2022 17:18:49 +0200 Subject: [PATCH 2/2] feat: added environment variables for configuration feat: added SIGINT event for CTRL+C support --- README.md | 9 ++++++++- raumstatus.js | 11 ++++++++--- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 256172e..6ae4083 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,13 @@ Fionera fügte HTML5 Push notifications hinzu. Danach kleinere Änderungen und Erweiterungen von henne, zeus, smash. +## config via environment variablen + + PING_INTERVAL_MS default 60000 + MQTT_SERVER default 'mqtt://mqtt.ctdo.de + FLUKSO_URL default "/sensor/cf00e0b22230f4a8870af58f2b8719dd + FLUKSO_HOST default"flukso.raum.ctdo.de" + STATUS_POLL_HOST default "snapserv.ctdo.de" ## Entrümpelung 2022 @@ -30,7 +37,7 @@ Danach kleinere Änderungen und Erweiterungen von henne, zeus, smash. Das meiste an Funktionn wurde wiede raus geworfen weil sich die CTDO infrastruktur 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. +Der Status zeigt nur noch Power und Raumstatus an. Es läuft wie gehabt via ICMP Ping. diff --git a/raumstatus.js b/raumstatus.js index a398e35..383ce28 100644 --- a/raumstatus.js +++ b/raumstatus.js @@ -8,6 +8,7 @@ var IpPoll = require("./ip-poll"); var routes = require("./routes"); var path = require('path'); var mqttClient = require('mqtt'); +var process = require('process') var spaceanswer = { api: "0.13", @@ -63,16 +64,20 @@ var spaceanswer = { var simpleanswer = {state: "unknown", lastchange: 0, power: 0}; -var ippoll = new IpPoll("rpi3.raum.ctdo.de"); +var ippoll = new IpPoll(process.env.STATUS_POLL_HOST || "snapserv.ctdo.de"); var flukso = new Flukso(process.env.FLUKSO_HOST || "flukso.raum.ctdo.de", process.env.FLUKSO_URL || "/sensor/cf00e0b22230f4a8870af58f2b8719dd"); var mqtt = mqttClient.connect(process.env.MQTT_SERVER || 'mqtt://mqtt.ctdo.de'); var connected = false; //express js settings -var port = '9911'; +var port = process.env.HTTP_PORT || '9911'; var address = '0.0.0.0'; +process.on('SIGINT', () => { + console.info("Interrupted") + process.exit(0) +}) ippoll.on('doneState', function (state) { spaceanswer.state.open = state; @@ -114,7 +119,7 @@ function work() { sendSimple(); } -setInterval(work, 60000); +setInterval(work, process.env.PING_INTERVAL_MS || 60000); work(); setInterval(flukso.pollPower, 5000); -- 2.40.1