-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmbus-client.html
204 lines (179 loc) · 8.35 KB
/
mbus-client.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
195
196
197
198
199
200
201
202
203
204
<script type="text/javascript">
RED.nodes.registerType('mbus-client', {
category: 'config',
defaults: {
name: {value: ''},
clienttype: {value: 'tcp', required: true},
tcpHost: {value: '127.0.0.1', required: true},
tcpPort: {value: 10001, required: true, validate: RED.validators.number()},
tcpTimeout: {value: 4000, required: true, validate: RED.validators.number()},
serialPort: {value: '/dev/ttyUSB', required: true},
serialBaudrate: {value: 2400, required: true, validate: RED.validators.number()},
reconnectTimeout: {value: 10000, required: true, validate: RED.validators.number()},
autoScan: {value: true},
storeDevices: {value: true},
disableLogs: {value: true}
},
label: function () {
let node = this
if (node.clienttype == 'tcp') {
return node.name || 'mbus-tcp@' + node.tcpHost + ':' + node.tcpPort
} else {
return node.name || 'mbus-serial@' + node.serialPort + ':' + node.serialBaudrate
}
},
oneditprepare: function () {
let previous = null
let node = this
node.ports = []
let clientTypeSelector = $('#node-config-input-clienttype')
let inputsSerial = $('#node-config-inputs-serial')
let inputsTCP = $('#node-config-inputs-tcp');
clientTypeSelector.on('focus', function () {
previous = this.value
}).change(function () {
if (previous == null) {
previous = $('#node-config-input-clienttype').val()
}
switch (clientTypeSelector.val()) {
case 'tcp':
inputsSerial.hide()
inputsTCP.show()
if (node.tcpHost) {
node.tcpHost.required = true
node.tcpPort.required = true
}
if (node.serialPort) {
node.serialPort.required = false
node.serialBaudrate.required = false
}
break
case 'serial':
inputsSerial.show()
inputsTCP.hide()
if (node.tcpHost) {
node.tcpHost.required = false
node.tcpPort.required = false
}
if (node.serialPort) {
node.serialPort.required = true
node.serialBaudrate.required = true
}
break
default:
break
}
})
try {
$('#node-config-input-serialPort').autocomplete('destroy')
}
catch (err) {
}
$('#node-config-lookup-serial').click(function () {
$('#node-config-lookup-serial').addClass('disabled')
$.getJSON('/mbus/serial/ports', function (data) {
$('#node-config-lookup-serial').removeClass('disabled')
node.ports = []
$.each(data, function (i, port) {
node.ports.push(port.path)
})
$('#node-config-input-serialPort').autocomplete({
source: node.ports,
minLength: 0,
close: function (event, ui) {
$('#node-config-input-serialPort').autocomplete('destroy')
}
}).autocomplete('search', '')
})
})
}
})
</script>
<script type="text/x-red" data-template-name="mbus-client">
<div class="form-row">
<label for="node-config-input-name"><i class="icon-tag"></i> <span data-i18n="node-red:common.label.name"></span></label>
<input type="text" id="node-config-input-name" placeholder="Name">
</div>
<div class="form-row">
<label for="node-config-input-clienttype"><i class="fa fa-plug"></i> <span data-i18n="mbus.label.type"></span></label>
<select type="text" id="node-config-input-clienttype" style="width:140px;">
<option value="tcp" select>TCP</option>
<option value="serial">Serial</option>
</select>
</div>
<hr>
<div id="node-config-inputs-tcp">
<div class="form-row">
<label for="node-config-input-tcpHost"><i class="fa fa-link"></i> <span data-i18n="mbus.label.host"></span></label>
<input type="text" id="node-config-input-tcpHost">
</div>
<div class="form-row">
<label for="node-config-input-tcpPort"><i class="fa fa-random"></i> <span data-i18n="mbus.label.port"></span></label>
<input type="text" id="node-config-input-tcpPort" placeholder="2000">
</div>
<div class="form-row">
<label for="node-config-input-tcpTimeout"><i class="icon-time"></i> <span data-i18n="mbus.label.reconnectTimeout"></span></label>
<input type="text" id="node-config-input-tcpTimeout" placeholder="4000">
</div>
</div>
<div id="node-config-inputs-serial">
<div class="form-row">
<label for="node-config-input-serialPort"><i class="fa fa-random"></i> <span data-i18n="mbus.label.serialport"></span></label>
<input type="text" id="node-config-input-serialPort" style="width:60%;" placeholder="/dev/ttyUSB or COM4">
<a id="node-config-lookup-serial" class="btn"><i id="node-config-lookup-serial-icon" class="fa fa-search"></i></a>
</div>
<div class="form-row">
<label for="node-config-input-serialBaudrate"><i class="icon-bookmark"></i> <span data-i18n="mbus.label.baudRate"></span></label>
<select id="node-config-input-serialBaudrate" style="max-width:140px">
<option value="115200">115200</option>
<option value="57600">57600</option>
<option value="38400">38400</option>
<option value="19200">19200</option>
<option value="9600">9600</option>
<option value="4800">4800</option>
<option value="2400">2400</option>
<option value="1200">1200</option>
<option value="300">300</option>
<option value="110">110</option>
<option value="75">75</option>
</select>
</div>
</div>
<hr>
<div class="form-row">
<label for="node-config-input-reconnectTimeout"><i class="icon-time"></i> <span data-i18n="mbus.label.reconnectTimeout"></span></label>
<input type="text" id="node-config-input-reconnectTimeout" placeholder="10000">
</div>
<div class="form-row">
<label></label>
<input type="checkbox" id="node-config-input-autoScan" style="display: inline-block; width: auto; vertical-align: top;">
<label style="width:65%" for="node-config-input-autoScan"><span data-i18n="mbus.label.autoScan"></span></label>
</div>
<div class="form-row">
<label></label>
<input type="checkbox" id="node-config-input-storeDevices" style="display: inline-block; width: auto; vertical-align: top;">
<label style="width:65%" for="node-config-input-storeDevices"><span data-i18n="mbus.label.storeDevices"></span></label>
</div>
<div class="form-row">
<label></label>
<input type="checkbox" id="node-config-input-disableLogs" style="display: inline-block; width: auto; vertical-align: top;">
<label style="width:65%" for="node-config-input-disableLogs"><span data-i18n="mbus.label.disableLogs"></span></label>
</div>
</script>
<script type="text/x-red" data-help-name="mbus-client">
<p>Configuration node that connects to a TCP/Serial M-Bus client.</p>
<h3>Details</h3>
Initializes the MBusMaster instance to interact with the devices.
<h3>Parameters</h3>
<ul>
<li><b>host/port</b>: For TCP communication you set the host and the port to connect to. Both parameters are mandatory</li>
<li><b>serialPort/serialBaudRate</b>: For Serial communication you set the serialPort (e.g. /dev/ttyUSB0) and the serialBaudRate to connect. Default Baudrate is 2400 baut if option is missing</li>
<li><b>Reconnect timoeut</b>: Milliseconds to wait between two reconnection tries</li>
<li><b>Auto scan and read</b>: If true the node, once connected, will automatically scan the Mbus network and start reading found devices</li>
<li><b>Store scanned devices</b>: If auto scan and read is enabled and this options is true, the node, once connected, will check for existing file <code>mbus_devices_<clientName>.json</code> in <code>.node-red</code> directory, if it doesn't exist it will do the scan and create one with found devices</li>
</ul>
<h3>References</h3>
<ul>
<li><a href="https://github.com/robertsLando/node-red-contrib-m-bus">GitHub</a> - the node github repository</li>
</ul>
</script>