geofences started
This commit is contained in:
38
dist/GeoFences.js
vendored
Normal file
38
dist/GeoFences.js
vendored
Normal file
@ -0,0 +1,38 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const express = require("express");
|
||||
const logger = require("./log");
|
||||
const bodyParser = require("body-parser");
|
||||
const config = require("./config");
|
||||
const MqttDispatcher_1 = require("./MqttDispatcher");
|
||||
class GeoFences {
|
||||
constructor() {
|
||||
this.app = express();
|
||||
this.app.use(bodyParser.urlencoded({ extended: false }));
|
||||
this.app.use(bodyParser.json());
|
||||
}
|
||||
exec() {
|
||||
this.app.post('/', (req, res) => {
|
||||
const reqData = req.body;
|
||||
const deviceId = reqData.device;
|
||||
let occupantName = 'unknown';
|
||||
const location = reqData.name;
|
||||
if (deviceId in config.dict.occupants) {
|
||||
occupantName = config.dict.occupants[deviceId];
|
||||
}
|
||||
const direction = (reqData.entry == '1') ? 'arrives at' : 'leaves from';
|
||||
logger.info(`${deviceId} (${occupantName}) ${direction} ${location}`);
|
||||
logger.info(JSON.stringify(reqData));
|
||||
res.send('OK');
|
||||
const state = (reqData.entry == '1') ? 'present' : 'absent';
|
||||
MqttDispatcher_1.mqttHandler.send(`${GeoFences.geoFencesTopicPre}/${occupantName}`, state);
|
||||
});
|
||||
let port = parseInt(config.dict.geofencesPort);
|
||||
this.server = this.app.listen(port, '', () => {
|
||||
logger.info(`geofences server listening on ${port}`);
|
||||
});
|
||||
}
|
||||
}
|
||||
GeoFences.geoFencesTopicPre = "dispatcher_ng/geofences";
|
||||
exports.GeoFences = GeoFences;
|
||||
//# sourceMappingURL=GeoFences.js.map
|
4
dist/main.js
vendored
4
dist/main.js
vendored
@ -20,6 +20,7 @@ const Cron_1 = require("./Cron");
|
||||
const HueColorBulbItem_1 = require("./HueColorBulbItem");
|
||||
const TouchSwitchMultiButtonThing_1 = require("./TouchSwitchMultiButtonThing");
|
||||
const RelayBox_1 = require("./RelayBox");
|
||||
const GeoFences_1 = require("./GeoFences");
|
||||
logger.info("Dispatcher starting");
|
||||
let allLabeledItems = new Array();
|
||||
// Anna -----------------------------------------------------------------------------------------------------
|
||||
@ -268,6 +269,9 @@ let relayBox = new RelayBox_1.RelayBoxThing('base', 'labor', 'relaybox', 'IoT/Co
|
||||
relayBox.start();
|
||||
allLabeledItems.push(relayBox);
|
||||
// ----------------------------------------------------------------------------------------------------------
|
||||
let geoFences = new GeoFences_1.GeoFences();
|
||||
geoFences.exec();
|
||||
// ----------------------------------------------------------------------------------------------------------
|
||||
let testFourButton = new HomematicFourButtonThing_1.HomematicFourButtonThing('Gnd', 'Hallway', 'TestButton', 9, [
|
||||
new HomematicFourButtonThing_1.HomematicFourButtonSingleItem('dispatcher_ng/items/Gnd/Hallway/Testlight/dimmerIn'),
|
||||
new HomematicFourButtonThing_1.HomematicFourButtonSingleItem('dispatcher_ng/items/Gnd/Hallway/DeskLight/timerIn'),
|
||||
|
Reference in New Issue
Block a user