node-red-contrib-netpie
Version:
Node-RED module for connecting to NETPIE IoT Platform
198 lines (170 loc) • 7.28 kB
HTML
<script type="text/javascript">
RED.nodes.registerType('shadow',{
category: 'netpie',
color: '#90cc90',
defaults: {
name : {value: "shadow"},
deviceconfig: {
value: "Default",
type: "deviceconfig"
},
active: {value: true},
subshadow: {value: true},
initshadow: {value: true},
labelmode: {value: 'indicator'},
outputmode: {value: 'updated'}
},
inputs:1,
outputs:1,
icon: "font-awesome/fa-lightbulb-o",
button: {
enabled: function() {
return true
},
visible: function() {
return true
},
onclick: function() {
var label = (this.name||this.body);
var node = this;
$.ajax({
url: "inject/"+this.id,
type:"POST",
success: function(resp, textStatus, xhr) {
RED.notify(node._("reload status and shadow",{label:label}),"success");
},
error: function(jqXHR,textStatus,errorThrown) {
}
});
}
},
outputLabels: ["shadow data ","device status"],
label: function() {
return this.name||"shadow";
},
oneditprepare: function() {
this.editor = RED.editor.createEditor({
id: 'node-input-topics-editor',
//mode: 'ace/mode/nrjavascript', // validate js
value: $("#node-input-topics").val(),
globals: {
msg:true,
context:true,
RED: true,
util: true,
flow: true,
global: true,
console: true,
Buffer: true,
setTimeout: true,
clearTimeout: true,
setInterval: true,
clearInterval: true
}
});
},
oneditsave: function() {
$("#node-input-topics").val(this.editor.getValue());
this.editor.destroy();
delete this.editor;
},
oneditcancel: function() {
this.editor.destroy();
delete this.editor;
}
});
</script>
<script type="text/x-red" data-template-name="shadow">
<div class="form-row">
<label for="node-input-active"><i class="icon-cog"></i> Active</label>
<input type="checkbox" id="node-input-active" style="margin-left:5px; vertical-align:top; width:auto;">
Enabled
</div>
<div class="form-row">
<label for="node-input-name"><i class="icon-tag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="Name">
</div>
<div class="form-row">
<label for="node-input-deviceconfig"><i class="icon-cog"></i> Device </label>
<input type="text" id="node-input-deviceconfig">
</div>
<div class="form-row">
<label for="node-input-subshadow"><i class="icon-cog"></i></label>
<input type="checkbox" id="node-input-subshadow" style="margin-left:5px; vertical-align:top; width:auto;"> Shadow updated
</div>
<div class="form-row">
<label for="node-input-initshadow"><i class="icon-cog"></i></label>
<input type="checkbox" id="node-input-initshadow" style="margin-left:5px; vertical-align:top; width:auto;"> Output shadow data on connected
</div>
<div class="form-row">
<label for="node-input-outputmode"></label> Output Mode
<select id="node-input-outputmode">
<option value="updated">Updated fields</option>
<option value="all">Entire shadow</option>
</select>
</div>
<div class="form-row">
<label for="node-input-labelmode"></label> Node Label
<select id="node-input-labelmode">
<option value="indicator">Status</option>
<option value="updated">Display updated shadow fields</option>
<option value="all">Display entire shadow data</option>
</select>
</div>
</script>
<script type="text/x-red" data-help-name="shadow">
<p>The Shadow node retrieves and monitors device shadow data without affecting the actual device behavior. It provides access to the virtual representation of device state stored in the cloud.</p>
<h3>Configuration</h3>
<dl class="message-properties">
<dt>Active</dt>
<dd>Enable/disable the node operation</dd>
<dt>Name</dt>
<dd>The name of the node displayed in the flow</dd>
<dt>Device</dt>
<dd>Select the device configuration to access shadow data from</dd>
<dt>Shadow updated</dt>
<dd>Enable to receive real-time notifications when shadow data is updated. If disabled, you can still get shadow data by manually triggering the node or using the button, but won't receive automatic updates when data changes.</dd>
<dt>Output shadow data on connected</dt>
<dd>Enable to output current shadow data immediately when connection is established</dd>
<dt>Output Mode</dt>
<dd>
<ul>
<li><b>Updated fields</b>: Output only the fields that have been updated</li>
<li><b>Entire shadow</b>: Output the complete shadow data structure</li>
</ul>
</dd>
<dt>Node Label</dt>
<dd>Choose what to display as the node label:
<ul>
<li><b>Status</b>: Show connection status indicator</li>
<li><b>Display updated shadow fields</b>: Show the updated field names</li>
<li><b>Display entire shadow data</b>: Show complete shadow data</li>
</ul>
</dd>
</dl>
<h3>Input</h3>
<p>Accepts trigger messages to manually refresh shadow data:</p>
<pre>{
"data": {
"temp": 25.5,
"humid": 60.2,
"location": "Room A"
}
}</pre>
<h3>Button Function</h3>
<p>The node includes a button that can be clicked to manually reload the current shadow data and device status.</p>
<h3>Real-time vs Manual Mode</h3>
<ul>
<li><b>Real-time mode</b>: When "Shadow updated" is enabled, the node automatically receives notifications whenever shadow data changes</li>
<li><b>Manual mode</b>: When "Shadow updated" is disabled, you can still get shadow data by sending a message to the input or clicking the node button</li>
<li>Real-time mode requires a channel connection for notifications</li>
<li>Manual mode works without a channel and fetches data on-demand</li>
</ul>
<h3>Notes</h3>
<ul>
<li>This node is read-only and does not modify the actual device or its shadow</li>
<li>Shadow data represents the last known state of the device</li>
<li>The node requires proper device configuration with valid credentials</li>
<li>Useful for creating device twins for testing and development purposes</li>
</ul>
</script>