-
Notifications
You must be signed in to change notification settings - Fork 0
/
lo-device.js
34 lines (30 loc) · 1.16 KB
/
lo-device.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import dotenv from 'dotenv'
import LoDeviceController from "./service/LoDeviceController.js";
import log4js from "log4js";
import {loadJSON} from "./service/util.js";
const logger = log4js.getLogger("lo-device");
logger.level = 'DEBUG';
dotenv.config()
const mqttServerUrl = process.argv[2];
const deviceApiKey = process.argv[3];
const deviceId = process.argv[4];
try {
const loDeviceController = new LoDeviceController()
let deviceConfig = loDeviceController.buildDeviceConfigFromEnv({mqttServerUrl, deviceApiKey, deviceId});
const config = loadJSON("../data/initialConfig.json");
const resource = loadJSON("../data/initialResource.json");
deviceConfig = {...deviceConfig, config, resource};
loDeviceController.showHelp();
loDeviceController.startNewDevice(deviceConfig)
.then(() => {
loDeviceController.initAskAction();
}).catch(err => {
// cant start issue are already logged
})
} catch (exception) {
if ("code" in exception) {
logger.error(` Error: ${exception.code} : ${exception.details}`);
} else {
logger.error("unexpected error:", exception);
}
}