forked from anerdins/nibepi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
executable file
·78 lines (76 loc) · 2.99 KB
/
server.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
var nibe = require('./index.js');
process.on('exit', function(code) {
console.log('About to exit with code:', code);
if(code===-1) {
console.log('No serialport/host specified in config file')
} else if(code===-2) {
console.log('F series is only supported')
} else if(code===-3) {
console.log('The core could not be started')
}
});
console.log('Waiting for the core to initiate...')
let config = nibe.getConfig();
if(config.system.readonly!==false) {
config.system.readonly=false
nibe.setConfig(config);
}
if(config.home!==undefined) {
config.home=undefined;
nibe.setConfig(config);
}
if(config.hotwater!==undefined) {
config.hotwater=undefined;
nibe.setConfig(config);
}
if(config.indoor!==undefined) {
config.indoor=undefined;
nibe.setConfig(config);
}
if(config.fan!==undefined) {
config.fan=undefined;
nibe.setConfig(config);
}
nibe.setDocker(true);
if(config.connection!==undefined) {
if(config.connection.enable=="serial") {
if(config.serial!==undefined && config.serial.port!==undefined && config.serial.port!=="") {
if(config.connection.series!==undefined && config.connection.series!=="" && config.connection.series==="fSeries") {
nibe.initiateCore(null,config.serial.port, function(err,core) {
if(err) return process.exit(-3);
console.log('Core is started.')
})
} else {
process.exit(-2)
}
} else {
process.exit(-1);
}
} else if(config.connection.enable=="nibegw") {
if(config.serial!==undefined && config.serial.port!==undefined && config.serial.port!=="") {
if(config.connection.series!==undefined && config.connection.series!=="" && config.connection.series==="fSeries") {
nibe.initiateCore(null,config.serial.port, function(err,core) {
if(err) return process.exit(-3);
console.log('Core is started.')
})
} else {
process.exit(-2)
}
} else {
process.exit(-1);
}
} else if(config.connection.enable=="tcp") {
}
}
if(config.mqtt!==undefined) {
if(config.mqtt.enable!==undefined && config.mqtt.enable===true) {
const mqtt_host = config.mqtt.host;
const mqtt_port = config.mqtt.port;
const mqtt_user = config.mqtt.user;
const mqtt_pass = config.mqtt.pass;
nibe.handleMQTT(true,mqtt_host,mqtt_port,mqtt_user,mqtt_pass,function(err,result) {
if(err) return console.log(err);
})
console.log('Waiting for MQTT')
}
}