node-red-contrib-mnubo
Version:
Mnubo
132 lines (127 loc) • 5.67 kB
HTML
<script type="text/javascript">
RED.nodes.registerType('mnubo events', {
category: 'SmartObjects',
color: '#00a1e0',
defaults: {
name: { value: '' },
mnuboconfig: { value: '', type: 'mnubo config', required: true },
functionselection: { value: 'send', required: true },
inputtext: { value: '', type: 'text' },
reportResults: { value: false },
objectsMustExist: { value: false },
},
inputs: 1,
outputs: 1,
icon: 'Events.png',
align: 'left',
label: function() {
return this.name || 'event ' + this.functionselection;
},
labelStyle: function() {
return this.name ? 'node_label_italic' : '';
},
button: {
onclick: function() {
var label = this.name || 'button';
var node = this;
$.ajax({
url: 'events/' + this.id + '/button',
type: 'POST',
success: function(resp, textStatus, xhr) {
RED.notify(node._('local injection', { label: label }), 'success');
},
error: function(resp, textStatus, xhr) {
RED.notify(node._('local injection', { label: label }), 'error');
},
});
},
},
});
</script>
<script type="text/x-red" data-template-name="mnubo events">
<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"></input>
</div>
<div class="form-row">
<label for="node-input-mnuboconfig"><i class="fa fa-database"></i> mnubo config</label>
<input type="text" id="node-input-mnuboconfig"></input>
</div>
<div class="form-row">
<label for="node-input-functionselection"><i class="fa fa-list"></i> Function</label>
<select type="text" id="node-input-functionselection" style="width: 70%;">
<option value="send">Send</option>
<option value="sendfromdevice">SendFromDevice</option>
</select>
</div>
<div class="form-row">
<input type="checkbox" id="node-input-reportResults" style="display: inline-block; width: auto; vertical-align: top;"></input>
<label for="node-input-reportResults" style="width:auto" >Report Results</label>
</div>
<div class="form-row">
<input type="checkbox" id="node-input-objectsMustExist" style="display: inline-block; width: auto; vertical-align: top;"></input>
<label for="node-input-objectsMustExist" style="width:auto">Objects Must Exist</label>
</div>
<div class="form-row">
<label for="node-input-inputtext" style="vertical-align: top;"><i class="fa fa-pencil"></i> Input</label>
<textarea id="node-input-inputtext" rows="10" placeholder="optional input string" style="width: 70%;"></textarea>
</div>
</script>
<script type="text/x-red" data-help-name="mnubo events">
<p>This is a SmartObjects Ingestion Event node.</p>
<h3>Inputs</h3>
<ul>
<li>you can press the button to inject the input, using this node optional input</li>
<li>you can inject the input of a msg.payload</li>
</ul>
<h3>Outputs</h3>
<ul>
<li>The straight response coming from SmartObjects Platform can be found on "msg.payload"</li>
<li>If <u>Report Result</u> flag is set to "true", you can also refer to "msg.errors" in order to check the errorMessage and the originalRequest that has produced the error.</li>
</ul>
<h3>Details</h3>
<ul>
<li><b>Send:</b> The input needs to be a valid JSON with mandatory <i>"x_device_id"</i> and <i>"x_event_type"</i> attributes.</li>
<p>Example:</p>
<pre style="font-size: 12px;line-height: normal;padding-top: 4px;padding-bottom: 4px">msg.payload =
[
{
"x_object": {
"x_device_id": "object_500"
},
"x_event_type": "BoilerReport",
"temperature": 60.5
},
... (upto 1000 events)
]</pre>
<li><b>SendFromDevice:</b> The input is an "array" with [<i>"x_device_id"</i>, <i>"json body"</i>]</li>
<p>Example:</p>
<pre style="font-size: 12px;line-height: normal;padding-top: 4px;padding-bottom: 4px;">msg.payload =
["object_500",
[
{"x_event_type": "BoilerReport",
"temperature": 60.5
},
... (upto 1000 events)
]
]</pre>
</ul>
<h3>Requirements</h3>
<ol>
<li>
<b>Mnubo Configuration:</b> A valid Environment and Credentials.
</li>
<li>
<b>Report Results (OPTIONAL):</b> This flag can be added to indicate if event results are returned. When this flag is not used, it behaves as set to false.
</li>
<li>
<b>Objects Must Exist (OPTIONAL):</b> This flag can be added to ensure an Object exists before registering the event. If this flag is not used, it behaves as set to false.
</li>
</ol>
<p>To use SmartObjects nodes, you will need to have a valid mnubo account, with access granted on a namespace. To obtain your unique namespace in the SmartObjects platform, contact sales@mnubo.com . Please use the subject title <b>node-red-contrinb-mnubo</b> and include in the body of the email the name of your company, contact name and phone number.</p>
<h3>References</h3>
<ul>
<li><a href="https://smartobjects.mnubo.com/documentation/api_ingestion.html#events" target="_blank">SmartObjects online documentation </a> - (under the API section) for details about this interface usage. </li>
<li><a href="https://github.com/mnubo/node-red-contrib-mnubo" target="_blank">GitHub</a> - the nodes github repository</li>
</ul>
</script>