forked from anerdins/node-red-contrib-nibepi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config_node.html
executable file
·194 lines (191 loc) · 10.5 KB
/
config_node.html
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
<script type="text/javascript">
RED.nodes.registerType('nibe-config',{
category: 'config',
defaults: {
mqtt: {value:false,required:false},
mqtt_discovery: {value:false,required:false},
mqtt_topic: {value:"",required:false},
mqtt_host: {value:"127.0.0.1",required:false},
mqtt_port: {value:"1883",required:false},
mqtt_user: {value:"",required:false},
mqtt_pass: {value:"",required:false},
readonly: {value:false,required:false},
connection_series: {value:"fSeries",required:true},
connection: {value:"serial",required:true},
serial_port: {value:"/dev/ttyAMA0",required:false},
nibegw: {value:"",required:false},
tcp_server: {value:"",required:false},
tcp_port: {value:"",required:false}
},
label: function() {
return this.serial_port;
},
oneditprepare: function() {
$.getJSON('/config', function(data) {
$("#node-config-input-readonly").val(data.system.readonly);
$("#node-config-input-mqtt").val(data.mqtt.enable);
$("#node-config-input-mqtt_discovery").val(data.mqtt.discovery);
$("#node-config-input-mqtt_topic").val(data.mqtt.topic);
$("#node-config-input-mqtt_host").val(data.mqtt.host);
$("#node-config-input-mqtt_port").val(data.mqtt.port);
$("#node-config-input-mqtt_user").val(data.mqtt.user);
$("#node-config-input-mqtt_pass").val(data.mqtt.pass);
$("#node-config-input-connection").val(data.connection.enable)
$("#node-config-input-connection_series").val(data.connection.series)
$("#node-config-input-serial_port").val(data.serial.port);
$("#node-config-input-nibegw").val(data.serial.port);
$("#node-config-input-tcp_server").val(data.tcp.server);
$("#node-config-input-tcp_port").val(data.tcp.port);
showHide();
$("#node-config-input-connection_series").change(showHide);
$("#node-config-input-connection").change(showHide);
})
function showHide() {
if($("#node-config-input-connection_series").val()=="sSeries") {
$("#node-config-input-connection").val('tcp')
$("#node-config-input-serial_port").hide()
$("#node-config-input-nibegw").hide();
$("#node-config-input-tcp_server").show();
$("#node-config-input-tcp_port").show();
$('#node-config-input-connection option[value="serial"]').hide();
$('#node-config-input-connection option[value="nibegw"]').hide();
$('#node-config-input-connection option[value="tcp"]').show();
} else if($("#node-config-input-connection_series").val()=="fSeries") {
if($("#node-config-input-connection").val()=="tcp") {
$("#node-config-input-connection").val('serial')
}
if($("#node-config-input-connection").val()=="nibegw") {
$("#node-config-input-nibegw").show();
$("#node-config-input-serial_port").hide()
} else if($("#node-config-input-connection").val()=="serial") {
$("#node-config-input-nibegw").hide();
$("#node-config-input-serial_port").show()
}
$("#node-config-input-tcp_server").hide();
$("#node-config-input-tcp_port").hide();
$('#node-config-input-connection option[value="serial"]').show();
$('#node-config-input-connection option[value="nibegw"]').show();
$('#node-config-input-connection option[value="tcp"]').hide();
}
}
},
oneditsave: function() {
let node = this;
$.getJSON('/config', function(data) {
if(data===undefined) return;
if(data.mqtt===undefined) data.mqtt = {};
if(data.connection===undefined) data.connection = {};
if(data.serial===undefined) data.serial = {};
if(data.tcp===undefined) data.tcp = {};
if ($('#node-config-input-readonly').is(':checked')) {
data.system.readonly = true;
} else {
data.system.readonly = false;
}
if ($('#node-config-input-mqtt').is(':checked')) {
data.mqtt.enable = true;
} else {
data.mqtt.enable = false;
}
if ($('#node-config-input-mqtt_discovery').is(':checked')) {
data.mqtt.discovery = true;
} else {
data.mqtt.discovery = false;
}
//data.mqtt.enable = $("#node-config-input-mqtt").val();
if($("#node-config-input-mqtt_topic").val()!==undefined) data.mqtt.topic = $("#node-config-input-mqtt_topic").val();
if($("#node-config-input-mqtt_host").val()!==undefined) data.mqtt.host = $("#node-config-input-mqtt_host").val();
if($("#node-config-input-mqtt_port").val()!==undefined) data.mqtt.port = $("#node-config-input-mqtt_port").val();
if($("#node-config-input-mqtt_user").val()!==undefined) data.mqtt.user = $("#node-config-input-mqtt_user").val();
if($("#node-config-input-mqtt_pass").val()!==undefined) data.mqtt.pass = $("#node-config-input-mqtt_pass").val();
if($("#node-config-input-connection").val()!==undefined) data.connection.enable = $("#node-config-input-connection").val();
if($("#node-config-input-connection_series").val()!==undefined) data.connection.series = $("#node-config-input-connection_series").val();
if(data.connection.enable=="nibegw") {
if($("#node-config-input-nibegw").val()!==undefined) data.serial.port = $("#node-config-input-nibegw").val();
} else {
if($("#node-config-input-serial_port").val()!==undefined) data.serial.port = $("#node-config-input-serial_port").val();
}
if($("#node-config-input-tcp_server").val()!==undefined) data.tcp.server = $("#node-config-input-tcp_server").val();
if($("#node-config-input-tcp_port").val()!==undefined) data.tcp.port = $("#node-config-input-tcp_port").val();
let out = {data:node,config:data};
$.ajax({
contentType: 'application/json',
data: JSON.stringify(out),
dataType: 'json',
success: function(data){
app.log("device control succeeded");
},
error: function(){
app.log("Device control failed");
},
processData: false,
type: 'POST',
url: "config/"+node.id
});
})
}
});
</script>
<script type="text/x-red" data-template-name="nibe-config">
<div class="form-row">
<label for="node-config-input-connection_series"><i class="icon-bookmark"></i> Nibe Series</label>
<select id="node-config-input-connection_series">
<option value="fSeries">F-series</option>
<option value="sSeries">S-series</option>
</select>
</div>
<div class="form-row">
<label for="node-config-input-connection"> Connection</label>
<select id="node-config-input-connection">
<option value="serial">Serial</option>
<option value="tcp">TCP</option>
<option value="nibegw">NibeGW</option>
</select>
</div>
<div class="form-row">
<label for="node-config-input-serial_port"></i> Serialport</label>
<input type="text" id="node-config-input-serial_port" placeholder="/dev/ttyAMA0">
</div>
<div class="form-row">
<label for="node-config-input-nibegw"> NibeGW Host</label>
<input type="text" id="node-config-input-nibegw">
</div>
<div class="form-row">
<label for="node-config-input-tcp_server"><i class="icon-bookmark"></i> TCP Server</label>
<input type="text" id="node-config-input-tcp_server">
<label for="node-config-input-tcp_port"><i class="icon-bookmark"></i> TCP Port</label>
<input type="text" id="node-config-input-tcp_port">
</div>
<div class="form-row">
<label for="node-config-input-readonly"><i class="icon-bookmark"></i> Use read-only mode</label>
<input type="checkbox" id="node-config-input-readonly">
</div>
<div class="form-row">
<label for="node-config-input-mqtt"><i class="icon-bookmark"></i> Use Mosquitto broker</label>
<input type="checkbox" id="node-config-input-mqtt">
</div>
<div class="form-row">
<label for="node-config-input-mqtt_discovery"><i class="icon-bookmark"></i> Use Discovery</label>
<input type="checkbox" id="node-config-input-mqtt_discovery">
</div>
<div class="form-row">
<label for="node-config-input-mqtt_topic"><i class="icon-bookmark"></i> Topic</label>
<input type="text" id="node-config-input-mqtt_topic" placeholder="nibe/modbus/">
</div>
<div class="form-row">
<label for="node-config-input-mqtt_host"><i class="icon-bookmark"></i> Host</label>
<input type="text" id="node-config-input-mqtt_host">
</div>
<div class="form-row">
<label for="node-config-input-mqtt_port"><i class="icon-bookmark"></i> Port</label>
<input type="text" id="node-config-input-mqtt_port">
</div>
<div class="form-row">
<label for="node-config-input-mqtt_user"><i class="icon-bookmark"></i> User</label>
<input type="text" id="node-config-input-mqtt_user">
</div>
<div class="form-row">
<label for="node-config-input-mqtt_pass"><i class="icon-bookmark"></i> Password</label>
<input type="password" id="node-config-input-mqtt_pass">
</div>
</script>