-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathindex.js
executable file
·44 lines (36 loc) · 1.07 KB
/
index.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
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/env node
const cli = require('./cli');
const mqtt = require('./mqtt');
const renogy = require('./renogy');
const logger = require('./logger');
async function main() {
logger.info('Starting NodeRenogy...');
try {
const args = cli.args;
logger.trace(args, 'With arguments...')
await renogy.begin();
const controllerInfo = await renogy.getControllerInfo();
logger.trace(controllerInfo, 'Controller Info...');
if(args.mqttbroker) {
await mqtt.publish(controllerInfo, 'device');
}
setInterval(
async function() {
const result = await renogy.getData();
if(args.mqttbroker) {
await mqtt.publish(result, 'state');
}
else {
logger.trace('No MQTT broker specified!');
console.log(result);
}
},
args.pollinginterval * 1000
);
}
catch(e) {
logger.error(e);
process.exit(1);
}
}
main();