node-red-contrib-looptimer-advanced 0.0.12 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/README.md +194 -56
- package/looptimer_advanced.html +187 -67
- package/looptimer_advanced.js +429 -168
- package/package.json +26 -9
package/looptimer_advanced.html
CHANGED
|
@@ -1,67 +1,187 @@
|
|
|
1
|
-
<script type="text/javascript">
|
|
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
|
-
|
|
1
|
+
<script type="text/javascript">
|
|
2
|
+
(function () {
|
|
3
|
+
// Settings can be a number, or a msg., flow., global. or env. value
|
|
4
|
+
function typedNumber(typeField) {
|
|
5
|
+
return function (value) {
|
|
6
|
+
if ((this[typeField] || 'num') !== 'num') { return !!value; }
|
|
7
|
+
return RED.validators.number()(value);
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
const numericTypes = ['num', 'msg', 'flow', 'global', 'env'];
|
|
11
|
+
|
|
12
|
+
RED.nodes.registerType('looptimer-advanced', {
|
|
13
|
+
category: 'function',
|
|
14
|
+
color: "#33B2FF",
|
|
15
|
+
defaults: {
|
|
16
|
+
duration: { value: "5", required: true, validate: typedNumber('durationType') },
|
|
17
|
+
durationType: { value: "num" },
|
|
18
|
+
units: { value: "Second" },
|
|
19
|
+
maxloops: { value: "100", required: false, validate: typedNumber('maxloopsType') },
|
|
20
|
+
maxloopsType: { value: "num" },
|
|
21
|
+
totalcount: { value: false },
|
|
22
|
+
sendfirst: { value: true },
|
|
23
|
+
maxtimeout: { value: "1", required: false, validate: typedNumber('maxtimeoutType') },
|
|
24
|
+
maxtimeoutType: { value: "num" },
|
|
25
|
+
maxtimeoutunits: { value: "Hour" },
|
|
26
|
+
concurrency: { value: "restart" },
|
|
27
|
+
pausecontrol: { value: true },
|
|
28
|
+
pausetimeout: { value: "", required: false, validate: function (v) { return v === undefined || v === "" || RED.validators.number()(v); } },
|
|
29
|
+
pausetimeoutunits: { value: "Minute" },
|
|
30
|
+
pauseaction: { value: "resume" },
|
|
31
|
+
addstate: { value: false },
|
|
32
|
+
name: { value: "" }
|
|
33
|
+
},
|
|
34
|
+
inputs: 1,
|
|
35
|
+
outputs: 2,
|
|
36
|
+
icon: "looptimer_advanced.png",
|
|
37
|
+
label: function () {
|
|
38
|
+
return this.name || this.duration + " " + this.units + " Loop";
|
|
39
|
+
},
|
|
40
|
+
labelStyle: function () {
|
|
41
|
+
return this.name ? "node_label_italic" : "";
|
|
42
|
+
},
|
|
43
|
+
outputLabels: ["original msg", "stopped msg"],
|
|
44
|
+
oneditprepare: function () {
|
|
45
|
+
// Nodes saved by earlier versions do not have the newer settings, show the defaults
|
|
46
|
+
const defaults = { durationType: 'num', maxloopsType: 'num', maxtimeoutType: 'num', concurrency: 'restart', pausetimeoutunits: 'Minute', pauseaction: 'resume' };
|
|
47
|
+
Object.keys(defaults).forEach((key) => {
|
|
48
|
+
if (!this[key]) { $('#node-input-' + key).val(defaults[key]); }
|
|
49
|
+
});
|
|
50
|
+
if (this.sendfirst === undefined) { $('#node-input-sendfirst').prop('checked', true); }
|
|
51
|
+
|
|
52
|
+
['duration', 'maxloops', 'maxtimeout'].forEach((field) => {
|
|
53
|
+
$('#node-input-' + field).typedInput({
|
|
54
|
+
default: 'num',
|
|
55
|
+
types: numericTypes,
|
|
56
|
+
typeField: '#node-input-' + field + 'Type'
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
$('#node-input-duration').typedInput('width', '150px');
|
|
60
|
+
$('#node-input-maxloops').typedInput('width', '150px');
|
|
61
|
+
$('#node-input-maxtimeout').typedInput('width', '150px');
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
})();
|
|
65
|
+
</script>
|
|
66
|
+
|
|
67
|
+
<script type="text/html" data-template-name="looptimer-advanced">
|
|
68
|
+
<div class="form-row">
|
|
69
|
+
<label for="node-input-duration"><i class="fa fa-clock-o"></i> Loop Every</label>
|
|
70
|
+
<input type="text" id="node-input-duration">
|
|
71
|
+
<input type="hidden" id="node-input-durationType">
|
|
72
|
+
<select id="node-input-units" style="width:120px !important">
|
|
73
|
+
<option value="Millisecond">Milliseconds</option>
|
|
74
|
+
<option value="Second">Seconds</option>
|
|
75
|
+
<option value="Minute">Minutes</option>
|
|
76
|
+
<option value="Hour">Hours</option>
|
|
77
|
+
<option value="Day">Days</option>
|
|
78
|
+
</select>
|
|
79
|
+
</div>
|
|
80
|
+
<div class="form-row">
|
|
81
|
+
<label for="node-input-maxloops"><i class="fa fa-repeat"></i> Max Loops</label>
|
|
82
|
+
<input type="text" id="node-input-maxloops">
|
|
83
|
+
<input type="hidden" id="node-input-maxloopsType">
|
|
84
|
+
</div>
|
|
85
|
+
<div class="form-row">
|
|
86
|
+
<label> </label>
|
|
87
|
+
<input type="checkbox" id="node-input-totalcount" style="display:inline-block; width:auto; vertical-align:top;">
|
|
88
|
+
<label for="node-input-totalcount" style="width:auto"> Max Loops counts the first message too</label>
|
|
89
|
+
</div>
|
|
90
|
+
<div class="form-row">
|
|
91
|
+
<label> </label>
|
|
92
|
+
<input type="checkbox" id="node-input-sendfirst" style="display:inline-block; width:auto; vertical-align:top;">
|
|
93
|
+
<label for="node-input-sendfirst" style="width:auto"> Send the first message immediately</label>
|
|
94
|
+
</div>
|
|
95
|
+
<div class="form-row">
|
|
96
|
+
<label for="node-input-maxtimeout"><i class="fa fa-clock-o"></i> Max Timeout</label>
|
|
97
|
+
<input type="text" id="node-input-maxtimeout">
|
|
98
|
+
<input type="hidden" id="node-input-maxtimeoutType">
|
|
99
|
+
<select id="node-input-maxtimeoutunits" style="width:120px !important">
|
|
100
|
+
<option value="Millisecond">Milliseconds</option>
|
|
101
|
+
<option value="Second">Seconds</option>
|
|
102
|
+
<option value="Minute">Minutes</option>
|
|
103
|
+
<option value="Hour">Hours</option>
|
|
104
|
+
<option value="Day">Days</option>
|
|
105
|
+
</select>
|
|
106
|
+
</div>
|
|
107
|
+
<div class="form-row">
|
|
108
|
+
<label for="node-input-concurrency"><i class="fa fa-random"></i> New message</label>
|
|
109
|
+
<select id="node-input-concurrency" style="width:270px !important">
|
|
110
|
+
<option value="restart">restarts the loop</option>
|
|
111
|
+
<option value="ignore">is ignored while a loop runs</option>
|
|
112
|
+
<option value="pertopic">starts a separate loop per msg.topic</option>
|
|
113
|
+
</select>
|
|
114
|
+
</div>
|
|
115
|
+
<div class="form-row">
|
|
116
|
+
<label> </label>
|
|
117
|
+
<input type="checkbox" id="node-input-pausecontrol" style="display:inline-block; width:auto; vertical-align:top;">
|
|
118
|
+
<label for="node-input-pausecontrol" style="width:auto"> Pause / resume / status with payload</label>
|
|
119
|
+
</div>
|
|
120
|
+
<div class="form-row">
|
|
121
|
+
<label for="node-input-pausetimeout"><i class="fa fa-pause"></i> Pause Timeout</label>
|
|
122
|
+
<input type="text" id="node-input-pausetimeout" placeholder="none" style="text-align:end; width:70px !important">
|
|
123
|
+
<select id="node-input-pausetimeoutunits" style="width:120px !important">
|
|
124
|
+
<option value="Millisecond">Milliseconds</option>
|
|
125
|
+
<option value="Second">Seconds</option>
|
|
126
|
+
<option value="Minute">Minutes</option>
|
|
127
|
+
<option value="Hour">Hours</option>
|
|
128
|
+
<option value="Day">Days</option>
|
|
129
|
+
</select>
|
|
130
|
+
</div>
|
|
131
|
+
<div class="form-row">
|
|
132
|
+
<label for="node-input-pauseaction"><i class="fa fa-step-forward"></i> After Timeout</label>
|
|
133
|
+
<select id="node-input-pauseaction" style="width:140px !important">
|
|
134
|
+
<option value="resume">resume the loop</option>
|
|
135
|
+
<option value="stop">stop the loop</option>
|
|
136
|
+
</select>
|
|
137
|
+
</div>
|
|
138
|
+
<div class="form-row">
|
|
139
|
+
<label> </label>
|
|
140
|
+
<input type="checkbox" id="node-input-addstate" style="display:inline-block; width:auto; vertical-align:top;">
|
|
141
|
+
<label for="node-input-addstate" style="width:auto"> Add the loop counters as msg.loopstate</label>
|
|
142
|
+
</div>
|
|
143
|
+
<div class="form-row">
|
|
144
|
+
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
|
|
145
|
+
<input type="text" id="node-input-name" placeholder="Name">
|
|
146
|
+
</div>
|
|
147
|
+
</script>
|
|
148
|
+
|
|
149
|
+
<script type="text/html" data-help-name="looptimer-advanced">
|
|
150
|
+
<p>Sends the <code>msg</code> through the first output, then repeats it once per the configured duration until it is stopped, the maximum number of loops is reached or the maximum timeout expires.</p>
|
|
151
|
+
|
|
152
|
+
<h3>Inputs</h3>
|
|
153
|
+
<dl class="message-properties">
|
|
154
|
+
<dt>payload <span class="property-type">string</span></dt>
|
|
155
|
+
<dd><code>stop</code> / <code>STOP</code> stops the loop. If enabled in the node, <code>pause</code>, <code>resume</code> and <code>status</code> do what they say. Any other message (re)starts the loop.</dd>
|
|
156
|
+
<dt class="optional">loop.command <span class="property-type">string</span></dt>
|
|
157
|
+
<dd><code>stop</code>, <code>pause</code>, <code>resume</code> or <code>status</code>. Works regardless of the payload and of the "Pause / resume / status with payload" setting.</dd>
|
|
158
|
+
<dt class="optional">loop.all <span class="property-type">boolean</span></dt>
|
|
159
|
+
<dd>With <code>true</code> a command applies to all loops of the node (see "New message" below).</dd>
|
|
160
|
+
<dt class="optional">loop.duration, loop.units <span class="property-type">number, string</span></dt>
|
|
161
|
+
<dd>Override the loop interval. Units: <code>Millisecond</code>, <code>Second</code>, <code>Minute</code>, <code>Hour</code>, <code>Day</code>.</dd>
|
|
162
|
+
<dt class="optional">loop.maxtimeout, loop.maxtimeoutunits <span class="property-type">number, string</span></dt>
|
|
163
|
+
<dd>Override the maximum timeout.</dd>
|
|
164
|
+
<dt class="optional">loop.maxloops <span class="property-type">number</span></dt>
|
|
165
|
+
<dd>Override the maximum number of loops.</dd>
|
|
166
|
+
<dt class="optional">loop.totalcount, loop.sendfirst, loop.loopstate <span class="property-type">boolean</span></dt>
|
|
167
|
+
<dd>Override "Max Loops counts the first message too", "Send the first message immediately" and "Add the loop counters".</dd>
|
|
168
|
+
<dt class="optional">loop.pausetimeout, loop.pausetimeoutunits, loop.pauseaction <span class="property-type">number, string, string</span></dt>
|
|
169
|
+
<dd>Override the pause timeout and what happens after it (<code>resume</code> or <code>stop</code>).</dd>
|
|
170
|
+
</dl>
|
|
171
|
+
|
|
172
|
+
<h3>Outputs</h3>
|
|
173
|
+
<ol class="node-ports">
|
|
174
|
+
<li>The original message, then once per loop. After a pause, the first message carries <code>msg.pauseduration</code> (milliseconds spent paused). With "Add the loop counters" every message carries <code>msg.loopstate</code>.</li>
|
|
175
|
+
<li>Status messages with payload <code>stopped</code>, <code>max loops reached</code>, <code>timeout</code>, <code>paused</code>, <code>resumed</code> or <code>status</code>. After an automatic resume or stop <code>msg.reason</code> is <code>pause timeout</code>.</li>
|
|
176
|
+
</ol>
|
|
177
|
+
|
|
178
|
+
<h3>msg.loopstate</h3>
|
|
179
|
+
<p><code>state</code> (<code>running</code>, <code>paused</code>, <code>stopped</code>, <code>finished</code> or <code>idle</code>), <code>count</code> (loop messages sent, the first one not included), <code>sent</code> (all messages), <code>max</code> and <code>remaining</code> (<code>null</code> when unlimited), <code>elapsed</code> (milliseconds the loop has been running, the time paused not included) and <code>interval</code> (milliseconds).</p>
|
|
180
|
+
|
|
181
|
+
<h3>Details</h3>
|
|
182
|
+
<p><b>Counting.</b> By default the first message is not part of the loop, so Max Loops <code>5</code> gives <code>6</code> messages. Tick "Max Loops counts the first message too" to get exactly the configured number: <code>1</code> is a single message, <code>0</code> sends nothing and <code>-1</code> is unlimited. Without "Send the first message immediately" the first message goes out after the first interval, so Max Loops <code>5</code> gives <code>5</code> messages.</p>
|
|
183
|
+
<p><b>New message.</b> By default a new message restarts the loop. "is ignored while a loop runs" drops it (also its settings) until the loop is over. "starts a separate loop per msg.topic" runs one loop per topic, <code>stop</code>, <code>pause</code>, <code>resume</code> and <code>status</code> then apply to the loop of the topic of the command, or to all loops with <code>msg.loop.all = true</code>.</p>
|
|
184
|
+
<p><b>Pause.</b> Pausing freezes the remaining time of the current interval, the loop counter and the timeout budget. With a pause timeout the loop is resumed or stopped automatically after that time.</p>
|
|
185
|
+
<p><b>Typed settings.</b> Loop Every, Max Loops and Max Timeout can be read from <code>msg.</code>, <code>flow.</code>, <code>global.</code> or <code>env</code> instead of being a fixed number.</p>
|
|
186
|
+
<p>Overrides in <code>msg.loop</code> stay in effect for the following messages.</p>
|
|
187
|
+
</script>
|