UNPKG

node-red-contrib-datacake-helpers

Version:

Node-RED nodes to interact with the Datacake GraphQL API for KPIs and device stats. Includes other helper nodes for device management.

76 lines (71 loc) 3.22 kB
<script type="text/javascript"> RED.nodes.registerType('datacakegraphql-device-post', { category: 'Datacake', color: '#3FADB5', defaults: { name: { value: "" }, apiUrl: { value: "", required: true }, serialNumber: { value: "" } }, inputs: 1, outputs: 1, icon: "icons/datacake.svg", label: function () { return this.name || "Datacake Device Post"; }, paletteLabel: "Device Post", oneditprepare: function() { // Any preparation code for the edit dialog } }); </script> <script type="text/html" data-template-name="datacakegraphql-device-post"> <div class="form-row"> <label for="node-input-name"><i class="fa fa-tag"></i> Name</label> <input type="text" id="node-input-name" placeholder="Name"> </div> <div class="form-row"> <label for="node-input-apiUrl"><i class="fa fa-globe"></i> API URL</label> <input type="text" id="node-input-apiUrl" placeholder="https://api.datacake.co/integrations/api/.../"> </div> <div class="form-row"> <label for="node-input-serialNumber"><i class="fa fa-barcode"></i> Serial Number</label> <input type="text" id="node-input-serialNumber" placeholder="Optional - can be set in message"> </div> </script> <script type="text/html" data-help-name="datacakegraphql-device-post"> <p>A node to post data to Datacake device API.</p> <h3>Inputs</h3> <dl class="message-properties"> <dt>payload <span class="property-type">object | any</span></dt> <dd>The data to send to the Datacake API. If it's an object, all properties will be included at the top level of the request. If it's not an object, it will be encapsulated in a "user_data" field.</dd> <dt class="optional">apiUrl <span class="property-type">string</span></dt> <dd>Optional URL to override the configured API URL.</dd> <dt class="optional">serialNumber <span class="property-type">string</span></dt> <dd>Optional serial number to override the configured one.</dd> </dl> <h3>Outputs</h3> <dl class="message-properties"> <dt>payload</dt> <dd>The response from the Datacake API.</dd> <dt>statusCode</dt> <dd>The HTTP status code from the API response.</dd> <dt class="optional">error</dt> <dd>Error message if the request failed.</dd> </dl> <h3>Details</h3> <p>This node posts data to a Datacake API endpoint in the format expected by Datacake's standard device decoder.</p> <p>The serial number will be included as the "device" field in the JSON payload.</p> <p>Data formatting:</p> <ul> <li>If the input payload is an object, its properties will be included at the top level of the request</li> <li>If the input payload is not an object (string, number, array, etc.), it will be encapsulated in a "user_data" field</li> </ul> <p>Example payload format when sent to Datacake:</p> <pre>{ "device": "your-serial-number", "temperature": 23.5, "humidity": 45, ...other fields from your payload }</pre> </script>