introduce configuration file
This commit is contained in:
7
config.json
Normal file
7
config.json
Normal file
@ -0,0 +1,7 @@
|
||||
{
|
||||
"brokerUrl": "mqtts://broker.hottis.de:8883",
|
||||
"brokerUser": "wn",
|
||||
"brokerPass": "locutus",
|
||||
"brokerCa": "/home/wn/server-ca.crt",
|
||||
"mongoDbUrl": "mongodb://localhost/hottis"
|
||||
}
|
13
dist/main.js
vendored
13
dist/main.js
vendored
@ -2,14 +2,23 @@
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const log = require("./log");
|
||||
const mqtt = require("./mqttdispatcher");
|
||||
const fs = require("fs");
|
||||
const cmdargs = require("command-line-args");
|
||||
const EspThermToJson = require("./espthermtojson");
|
||||
const MongoSave = require("./mongosave");
|
||||
log.info("Dispatcher starting");
|
||||
let dispatcher = new mqtt.MqttDispatcher("mqtts://broker.hottis.de:8883", "wn", "locutus", "/home/wn/server-ca.crt");
|
||||
const optionDefinitions = [
|
||||
{ name: 'verbose', alias: 'v', type: Boolean },
|
||||
{ name: 'config', alias: 'c', type: String, defaultValue: '~/mqttDispatcher.conf' }
|
||||
];
|
||||
const OPTIONS = cmdargs(optionDefinitions);
|
||||
log.info(`OPTIONS.config`);
|
||||
const CONFIG = JSON.parse(fs.readFileSync(OPTIONS.config, "utf8"));
|
||||
let dispatcher = new mqtt.MqttDispatcher(CONFIG.brokerUrl, CONFIG.brokerUser, CONFIG.brokerPass, CONFIG.brokerCa);
|
||||
dispatcher.register('IoT/espThermometer2/#', 'toJson', EspThermToJson.espThermToJson);
|
||||
let mongoUrl = "mongodb://localhost/hottis";
|
||||
// let mongoUrl = "mongodb://receiver:esp8266.@cluster0-shard-00-00-7qduq.mongodb.net:27017,cluster0-shard-00-01-7qduq.mongodb.net:27017,cluster0-shard-00-02-7qduq.mongodb.net:27017/hottis?ssl=true&replicaSet=Cluster0-shard-0&authSource=admin"
|
||||
let mongo = new MongoSave.MongoSave(mongoUrl);
|
||||
let mongo = new MongoSave.MongoSave(CONFIG.mongoDbUrl);
|
||||
dispatcher.register('IoT/espThermometer2/#', 'MongoSave', mongo);
|
||||
dispatcher.exec();
|
||||
log.info("Dispatcher running");
|
||||
|
@ -1,5 +1,9 @@
|
||||
0 info it worked if it ends with ok
|
||||
1 verbose cli [ '/usr/bin/nodejs', '/usr/bin/npm', 'start' ]
|
||||
1 verbose cli [ '/usr/bin/nodejs',
|
||||
1 verbose cli '/usr/bin/npm',
|
||||
1 verbose cli 'start',
|
||||
1 verbose cli '--',
|
||||
1 verbose cli '--config=/home/wn/workspace-node/Dispatcher/config.json' ]
|
||||
2 info using npm@3.10.10
|
||||
3 info using node@v6.11.2
|
||||
4 verbose run-script [ 'prestart', 'start', 'poststart' ]
|
||||
@ -7,12 +11,13 @@
|
||||
6 silly lifecycle dispatcher@1.0.0~prestart: no script for prestart, continuing
|
||||
7 info lifecycle dispatcher@1.0.0~start: dispatcher@1.0.0
|
||||
8 verbose lifecycle dispatcher@1.0.0~start: unsafe-perm in lifecycle true
|
||||
9 verbose lifecycle dispatcher@1.0.0~start: PATH: /usr/lib/node_modules/npm/bin/node-gyp-bin:/opt/services/MqttDispatcher/node_modules/.bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games
|
||||
10 verbose lifecycle dispatcher@1.0.0~start: CWD: /opt/services/MqttDispatcher
|
||||
11 silly lifecycle dispatcher@1.0.0~start: Args: [ '-c', 'node dist/main.js' ]
|
||||
9 verbose lifecycle dispatcher@1.0.0~start: PATH: /usr/lib/node_modules/npm/bin/node-gyp-bin:/home/wn/workspace-node/Dispatcher/node_modules/.bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/home/wn/.local/bin:/home/wn/bin:/opt/jdk/bin:/opt/apache-maven/bin:/home/wn/mos/bin
|
||||
10 verbose lifecycle dispatcher@1.0.0~start: CWD: /home/wn/workspace-node/Dispatcher
|
||||
11 silly lifecycle dispatcher@1.0.0~start: Args: [ '-c',
|
||||
11 silly lifecycle 'node dist/main.js "--config=/home/wn/workspace-node/Dispatcher/config.json"' ]
|
||||
12 silly lifecycle dispatcher@1.0.0~start: Returned: code: 1 signal: null
|
||||
13 info lifecycle dispatcher@1.0.0~start: Failed to exec start script
|
||||
14 verbose stack Error: dispatcher@1.0.0 start: `node dist/main.js`
|
||||
14 verbose stack Error: dispatcher@1.0.0 start: `node dist/main.js "--config=/home/wn/workspace-node/Dispatcher/config.json"`
|
||||
14 verbose stack Exit status 1
|
||||
14 verbose stack at EventEmitter.<anonymous> (/usr/lib/node_modules/npm/lib/utils/lifecycle.js:255:16)
|
||||
14 verbose stack at emitTwo (events.js:106:13)
|
||||
@ -23,20 +28,20 @@
|
||||
14 verbose stack at maybeClose (internal/child_process.js:891:16)
|
||||
14 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:226:5)
|
||||
15 verbose pkgid dispatcher@1.0.0
|
||||
16 verbose cwd /opt/services/MqttDispatcher
|
||||
17 error Linux 3.16.0-4-amd64
|
||||
18 error argv "/usr/bin/nodejs" "/usr/bin/npm" "start"
|
||||
16 verbose cwd /home/wn/workspace-node/Dispatcher
|
||||
17 error Linux 4.9.0-3-amd64
|
||||
18 error argv "/usr/bin/nodejs" "/usr/bin/npm" "start" "--" "--config=/home/wn/workspace-node/Dispatcher/config.json"
|
||||
19 error node v6.11.2
|
||||
20 error npm v3.10.10
|
||||
21 error code ELIFECYCLE
|
||||
22 error dispatcher@1.0.0 start: `node dist/main.js`
|
||||
22 error dispatcher@1.0.0 start: `node dist/main.js "--config=/home/wn/workspace-node/Dispatcher/config.json"`
|
||||
22 error Exit status 1
|
||||
23 error Failed at the dispatcher@1.0.0 start script 'node dist/main.js'.
|
||||
23 error Failed at the dispatcher@1.0.0 start script 'node dist/main.js "--config=/home/wn/workspace-node/Dispatcher/config.json"'.
|
||||
23 error Make sure you have the latest version of node.js and npm installed.
|
||||
23 error If you do, this is most likely a problem with the dispatcher package,
|
||||
23 error not with npm itself.
|
||||
23 error Tell the author that this fails on your system:
|
||||
23 error node dist/main.js
|
||||
23 error node dist/main.js "--config=/home/wn/workspace-node/Dispatcher/config.json"
|
||||
23 error You can get information on how to open an issue for this project with:
|
||||
23 error npm bugs dispatcher
|
||||
23 error Or if that isn't available, you can get their info via:
|
||||
|
@ -13,6 +13,7 @@
|
||||
"license": "ISC",
|
||||
"devDependencies": {
|
||||
"@types/chalk": "^0.4.31",
|
||||
"@types/command-line-args": "^4.0.1",
|
||||
"@types/mongodb": "^2.2.10",
|
||||
"@types/mqtt": "0.0.34",
|
||||
"@types/node": "^8.0.14",
|
||||
@ -20,6 +21,7 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"chalk": "^2.0.1",
|
||||
"command-line-args": "^4.0.7",
|
||||
"moment": "^2.18.1",
|
||||
"mongodb": "^2.2.31",
|
||||
"mqtt": "^2.9.2"
|
||||
|
17
src/main.ts
17
src/main.ts
@ -1,21 +1,30 @@
|
||||
import * as log from './log'
|
||||
import * as mqtt from './mqttdispatcher'
|
||||
import * as callchain from './callchain'
|
||||
import * as plugintest1 from './plugintest1'
|
||||
import * as fs from 'fs'
|
||||
import * as cmdargs from 'command-line-args'
|
||||
|
||||
import * as EspThermToJson from './espthermtojson'
|
||||
import * as MongoSave from './mongosave'
|
||||
|
||||
log.info("Dispatcher starting")
|
||||
let dispatcher = new mqtt.MqttDispatcher("mqtts://broker.hottis.de:8883",
|
||||
"wn", "locutus", "/home/wn/server-ca.crt")
|
||||
|
||||
const optionDefinitions = [
|
||||
{ name: 'verbose', alias: 'v', type: Boolean },
|
||||
{ name: 'config', alias: 'c', type: String, defaultValue: '~/mqttDispatcher.conf' }
|
||||
];
|
||||
const OPTIONS = cmdargs(optionDefinitions)
|
||||
const CONFIG = JSON.parse(fs.readFileSync(OPTIONS.config, "utf8"))
|
||||
|
||||
let dispatcher = new mqtt.MqttDispatcher(CONFIG.brokerUrl,
|
||||
CONFIG.brokerUser, CONFIG.brokerPass, CONFIG.brokerCa)
|
||||
|
||||
dispatcher.register('IoT/espThermometer2/#', 'toJson', EspThermToJson.espThermToJson)
|
||||
|
||||
|
||||
let mongoUrl = "mongodb://localhost/hottis"
|
||||
// let mongoUrl = "mongodb://receiver:esp8266.@cluster0-shard-00-00-7qduq.mongodb.net:27017,cluster0-shard-00-01-7qduq.mongodb.net:27017,cluster0-shard-00-02-7qduq.mongodb.net:27017/hottis?ssl=true&replicaSet=Cluster0-shard-0&authSource=admin"
|
||||
let mongo : MongoSave.MongoSave = new MongoSave.MongoSave(mongoUrl)
|
||||
let mongo : MongoSave.MongoSave = new MongoSave.MongoSave(CONFIG.mongoDbUrl)
|
||||
dispatcher.register('IoT/espThermometer2/#', 'MongoSave', mongo);
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user