-
Notifications
You must be signed in to change notification settings - Fork 1
/
MoonNode.html
458 lines (417 loc) · 20.3 KB
/
MoonNode.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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
<!--
Copyright JS Foundation and other contributors, http://js.foundation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<script type="text/html" data-template-name="moonNode-event">
<div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> <span data-i18n="common.label.name"> Name</span></label>
<input type="text" id="node-input-name" data-i18n="">
</div>
<div class="form-row">
<label for="node-input-interval"><span data-i18n="common.label.interval"> Interval (sec's)</span></label>
<input type="number" step=".01" id="node-input-interval" data-i18n="">
</div>
<div class="form-row">
<label for="node-input-delta"><span data-i18n="common.label.delta"> Change Delta</span></label>
<input type="number" step=".01" id="node-input-delta" data-i18n="">
</div>
<div class="form-row">
<label for="node-input-modelPath"><span data-i18n="common.label.modelPath"> Model Path</span></label>
<input type="text" id="node-input-modelPath" data-i18n="">
</div>
</script>
<script type="text/html" data-help-name="moonNode-event">
<p>Watches for a change to a specific object key value from the moonNode-Monitor node.</p>
<h3>Properties</h3>
<dl class="message-properties">
<dt>Model Path
<span class="property-type"> json path (eg: job.file.fileName)</span>
</dt>
<dd> The JSON path to monitor for changes </dd>
<dt class="optional">Interval <span class="property-type"> Number</span>
</dt>
<dd> Minimum duration to wait between duplicate events </dd>
<dt class="optional">Change Delta <span class="property-type"> Number</span></dt>
<dd> The amount the value must have changed by since the last triggered event.</dd>
</dl>
<h3>Outputs</h3>
<ol class="node-ports">
<li>Event Out
<dl class="message-properties">
<dt>msg.moonNode.eventValue <span class="property-type">(varies)</span></dt>
<dd>This object returns the value from the matching Model Path</dd>
<dt>msg.moonNode.lastEventValue <span class="property-type">(varies)</span></dt>
<dd>This object returns the value from the previous matching event</dd>
</dl>
</li>
</ol>
<h3>Details</h3>
<p>Use this node to watch for value changes to the object specified in 'Model Path'.
For example, to watch for changes to the current job name, set the 'Model Path' to <code>print_stats.filename</code>.
If the path contains a space it should be formatted like this <code>["temperature_sensor chamber"].temperature</code> (example).
Use 'Interval' & 'Change Delta' to control the frequecy that the node will trigger. This is useful when
watching for changes in the model which change very frequently eg. Temps.
</p>
<p>
The output msg will passthrough the <code>payload.fullModel</code>, <code>payload.patchModel</code>,
& <code>payload.prevModel</code>
received from the Monitor node.
</p>
<p>
To identify the correct model path for your use case, use a Debug node on the Monitor node to output the
Machine Model to the debug window. You can use the 'copy path' button & paste into 'Model Path'.
The 'Model Path' does not require any prefixes eg. <code>payload.fullModel</code>, <code>payload.patchModel</code>,
or <code>payload.prevModel</code>, so remove them from any pasted values.
</p>
<h3>References</h3>
<ul>
<li><a href="https://github.com/MintyTrebor/moonNode">GitHub</a> See the wiki for more information</li>
</ul>
</script>
<script type="text/html" data-template-name="moonNode-connector">
<div class="form-row">
<label for="node-config-input-server"><i class="fa fa-bookmark"></i> Moonraker WS (IP:Port)</label>
<input type="text" id="node-config-input-server" style="width: 70%">
</div>
<div class="form-row">
<label for="node-config-input-mrapi"><i class="fa fa-bookmark"></i> API Key</label>
<input type="text" id="node-config-input-mrapi" style="width: 70%">
</div>
<div class="form-row">
<p>Note: If you update an existing connection's parameters</p>
<p>you must deploy the flow before using the connection,</p>
<p>or refreshing MoonRaker objects list</p>
</div>
</script>
<script type="text/html" data-help-name="moonNode-connector">
<p>Connection details</p>
<h3>Details</h3>
<p>Enter the IP address & port of the Moonraker API. By default the moonraker api is on port 7125</p>
<p>If you have enabled authorization in Moonraker then enter the API key to authorise the connection</p>
<h3>References</h3>
<ul>
<li><a href="https://github.com/MintyTrebor/moonNode">GitHub</a> See the wiki for more information</li>
</ul>
</script>
<script type="text/html" data-template-name="moonNode-monitor">
<div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> <span data-i18n="common.label.name"> Name</span></label>
<input type="text" id="node-input-name" data-i18n="">
</div>
<div class="form-row">
<label for="node-input-server"><i class="fa fa-globe"></i><span data-i18n="moonNode-monitor.label.server"> moonNode WS (IP:Port)</span></label>
<input type="text" id="node-input-server" style="width: 70%"/>
</div>
<div class="form-row">
<label for="node-input-autoStart"><span data-i18n="moonNode-monitor.label.autoStart"> Auto Start</span></label>
<input type="checkbox" id="node-input-autoStart" checked="false">
</div>
<p><b>Select MoonRaker Objects to Monitor</b></p>
<div class="form-row">
<select id="node-input-mObjSel" multiple style="width: 70%; min-height: 300px"></select><span> </span><button id="node-input-getMN">Refresh</button>
</div>
<div class="form-row">
<span style="width: 70%"> (Use CTRL+Click to select multiple objects) </span>
</div>
<div class="form-row">
<span id="node-input-mObjMsg" style="color: red"></span>
</div>
<div class="form-row">
<input type="hidden" id="node-input-mObjList">
</div>
</script>
<script type="text/html" data-help-name="moonNode-monitor">
<p>Connects to Moonraker WebSocket, and subscribes to the objects selected.</p>
<h3>Properties</h3>
<dl class="message-properties">
<dt>Auto Start
<span class="property-type"> CheckBox</span>
</dt>
<dd> Set the monitor to autostart polling for information at boot/deployment</dd>
</dl>
<h3>Inputs</h3>
<ol class="node-ports">
<li>Monitor In
<dl class="message-properties">
<dt>payload.monitorState <span class="property-type"> String</span></dt>
<dd>Set to <code>ON</code> or <code>OFF</code> to start/stop the connection with Moonraker. Useful in scenarios where monitoring is not required 24/7. (EG. control by Start/Stop buttons on a dashboard)</dd>
</dl>
</li>
</ol>
<h3>Outputs</h3>
<ol class="node-ports">
<li>Model Out
<dl class="message-properties">
<dt>payload.fullModel <span class="property-type">JSON Object</span></dt>
<dd>This object conatins the latest full model from moonraker which has been combined with the latest patch update.</dd>
</dl>
<dl class="message-properties">
<dt>payload.patchModel <span class="property-type">JSON Object</span></dt>
<dd>This object contains the latest update from moonraker. A patch is a fragment of the full model - containing only the changed data since the last update.</dd>
</dl>
<dl class="message-properties">
<dt>payload.prevModel <span class="property-type">JSON Object</span></dt>
<dd>This object contains the previous full model before the latest patch update. Use this to compare current to previous versions of the model.</dd>
</dl>
</li>
<li>Connection Msgs
<dl class="message-properties">
<dd>Provides information about the connection state to moonraker - useful for debugging etc</dd>
</dl>
</li>
<li>RAW
<dl class="message-properties">
<dt>payload.RAW <span class="property-type">JSON Object</span></dt>
<dd>Provides the RAW output JSON from MoonRaker- useful for debugging etc</dd>
</dl>
</li>
</ol>
<h3>Details</h3>
<p>This is the main node, which creates the connection to MoonRaker.</p><br>
<p>Only 1 Monitor node should be deployed per node-red instance, to avoid creating too many sessions.
A single monitor node can provide updates to any other flows using the
'Link In' & 'Link Out' standard nodes.</p><br>
<p>Select the MoonRaker WS server(or add a new one), and click the refresh button to see the list of objects available to select. MoonRaker must be reachable on the network to retrieve a list of objects. The objects retrieved will be a compilation of standard MoonRaker objects and ones unique to your MoonRaker instance.</p><br>
<p></p>
<h3>References</h3>
<ul>
<li><a href="https://github.com/MintyTrebor/moonNode">GitHub</a> See the wiki for more information</li>
</ul>
<ul>
<li><a href="https://moonraker.readthedocs.io/en/latest/printer_objects/">MoonRaker</a> Object Documentation Reference</li>
</ul>
</script>
<script type="text/html" data-template-name="moonNode-command">
<div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> <span data-i18n="common.label.name"> Name</span></label>
<input type="text" id="node-input-name" data-i18n="">
</div>
<div class="form-row">
<label for="node-input-server"><i class="fa fa-globe"></i><span data-i18n="moonNode-monitor.label.server"> Moonraker IP</span></label>
<input type="text" id="node-input-server" style="width: 70%"/>
</div>
<div class="form-row">
<label for="node-input-command"><span data-i18n="common.label.command"> Command</span></label>
<input type="text" id="node-input-command" data-i18n="">
</div>
<div class="form-row">
<label for="node-input-stateless"><span data-i18n="common.label.stateless"> Stateless</span></label>
<input type="checkbox" id="node-input-stateless" value="false">
</div>
</script>
<script type="text/html" data-help-name="moonNode-command">
<p>Send a g-code or command to Moonraker. Triggered on an incomming msg.</p>
<h3>Properties</h3>
<dl class="message-properties">
<dt>Command
<span class="property-type"> String</span>
</dt>
<dd> The g-code or klipper command to send to MoonRaker. Note: A command set by <code>msg.payload.cmd</code> will override the command entered in the nodes UI. <code>msg.payload.cmd</code> commands will be queued and executed in the sequence they were received. The node will always wait for a response before sending the next command in the queue.</dd>
<dt>Stateless
<span class="property-type"> CheckBox</span>
</dt>
<dd> If enabled the node will not output any responses from MoonRaker. When disabled the node will display the response from MoonRaker when the command response has been recieved.</dd>
</dl>
<h3>Inputs</h3>
<ol class="node-ports">
<li>CMD In
<dl class="message-properties">
<dd>Triggers the Command on receipt of msg. If the msg contains <code>msg.payload.cmd</code> the node will use this value as the Command, overriding the Command property. Users can clear current queue by injecting <code>msg.payload.cmd</code> "CANCEL"
</dl>
</li>
</ol>
<h3>Outputs</h3>
<ol class="node-ports">
<li>CMD Out
<dl class="message-properties">
<dd>When the command is sent, or sent & completed (depending on <code>stateless</code> mode), the node will output the incoming msg object here.</dt>
</dl>
</li>
<li>CMD Response Data
<dl class="message-properties">
<dd>(Only active when stateless mode is disabled) - If the command returns data (eg probe height values) these values will be outputted here.</dt>
</dl>
</li>
<li>Error
<dl class="message-properties">
<dd>(Only active when stateless mode is disabled) - If the command returns an error the error information will be outputted here.</dt>
</dl>
</li>
</ol>
<h3>Details</h3>
<p>Use this node to send a command to Moonraker.</p>
<p>The output will passthrough the incoming msg object, after sending the command.</p>
<h3>References</h3>
<ul>
<li><a href="https://github.com/MintyTrebor/moonNode">GitHub</a> See the wiki for more information</li>
</ul>
</script>
<script type="text/javascript">
RED.nodes.registerType('moonNode-connector',{
color: "#0099ff",
category: 'config',
defaults: {
server: {value: "localhost:7125", required: true},
},
credentials: {
mrapi: {type: "text"},
},
label: function() {
return this.server;
},
paletteLabel: function() {
return "moonNode Connector";
}
});
RED.nodes.registerType('moonNode-monitor', {
color: "#0099ff",
category: 'moonNode-node',
defaults: {
name: {value:"moonNode Monitor"},
server: {value:"", type:"moonNode-connector", required:true},
autoStart : {value: false},
mObjSel : {value: null, required: true},
mObjList: {value: "{objects:[]}"}
},
inputs:1,
outputs:3,
icon: "font-awesome/fa-eye",
label: function() {
return this.name||this._("moonNode Monitor");
},
labelStyle: function() {
return this.name?"node_label_italic":"";
},
oneditprepare: function() {
var node = this;
var previousValueType = {value:"prev",label:this._("moonNode-monitor.previous"),hasValue:false};
var andLabel = this._("moonNode-monitor.and");
var caseLabel = this._("moonNode-monitor.ignorecase");
$("#node-input-getMN").click(function() {
if($("#node-input-server option:selected").text() != "Add new moonNode Connector..."){
$("#node-input-mObjMsg").text("");
getMRSubs();
}
});
$("#node-input-server").change(function() {
if($("#node-input-server option:selected").text() != "Add new moonNode Connector..."){
$("#node-input-getMN").prop('disabled', false);
}else{
$("#node-input-getMN").prop('disabled', true);
}
});
//disable the refresh button if no MRServer selected
if($("#node-input-server option:selected").text() == "Add new moonNode Connector..."){
$("#node-input-getMN").prop('disabled', true);
};
//construct the subscription selection
if(this.mObjSel){
//the user has previoulsy got and set objects from MR so retrieve the existing objects
var tmpConstruct3 = "";
var mObjListJSON = JSON.parse($("#node-input-mObjList").val());
$("#node-input-mObjSel").empty();
for(var b=0 in mObjListJSON.objects){
if(node.mObjSel.find(element => element == mObjListJSON.objects[b].object)){
tmpConstruct3 = `<option value="${mObjListJSON.objects[b].object}" selected>${mObjListJSON.objects[b].object}</option>`;
}else{
tmpConstruct3 = `<option value="${mObjListJSON.objects[b].object}">${mObjListJSON.objects[b].object}</option>`;
}
$("#node-input-mObjSel").append(tmpConstruct3);
}
};
async function getMRSubs(){
return $.getJSON('MRAPISub',{mnSvrID: $("#node-input-server").val()},function(data) {
var tmpConstruct2 = "";
$("#node-input-mObjSel").empty();
if(data.error){
$("#node-input-mObjMsg").text(data.error);
}
if(data.objects){
for(var c=0 in data.objects){
tmpConstruct2 = `<option value="${data.objects[c].object}">${data.objects[c].object}</option>`;
$("#node-input-mObjSel").append(tmpConstruct2);
}
$("#node-input-mObjList").val(JSON.stringify(data));
return true;
}else{
return false;
}
});
}
},
paletteLabel: function() {
return "moonNode Monitor";
},
inputLabels: "Monitor Input",
outputLabels: ["Model Out", "Connection Msgs", "RAW"]
});
RED.nodes.registerType('moonNode-command', {
color: "#0099ff",
category: 'moonNode-node',
defaults: {
name: {value:""},
command: {value:""},
server: {value:"", type:"moonNode-connector", required:true},
stateless: {value: false}
},
inputs: 1,
outputs: 3,
icon: "font-awesome/fa-microchip",
label: function() {
return this.name||this._("moonNode CMD");
},
labelStyle: function() {
return this.name?"node_label_italic":"";
},
oneditprepare: function() {
var node = this;
var previousValueType = {value:"prev",label:this._("moonNode-command.previous"),hasValue:false};
var andLabel = this._("moonNode-monitor.and");
var caseLabel = this._("moonNode-monitor.ignorecase");
},
paletteLabel: function() {
return "moonNode CMD";
},
inputLabels: "CMD In",
outputLabels: ["CMD Out", "CMD Response Data", "Error"]
});
RED.nodes.registerType('moonNode-event', {
color: "#0099ff",
category: 'moonNode-node',
defaults: {
name: {value:""},
interval: {value:"0"},
delta: {value:"0"},
modelPath: {value: null, required:true},
outputs: {value:1}
},
inputs: 1,
outputs: 1,
icon: "font-awesome/fa-cogs",
label: function() {
return this.name||this._("moonNode Event");
},
labelStyle: function() {
return this.name?"node_label_italic":"";
},
oneditprepare: function() {
var node = this;
var previousValueType = {value:"prev",label:this._("moonNode-event.previous"),hasValue:false};
var andLabel = this._("moonNode-event.and");
var caseLabel = this._("moonNode-event.ignorecase");
},
paletteLabel: function() {
return "moonNode Event";
},
inputLabels: "Model In",
outputLabels: "Event Out"
});
</script>