DevicePilot is the analytics, visualization, and automation tool for IoT. Plug in your data and get instant, powerful insights to track all the important metrics that your business depends on.
This library helps you quickly get started posting your device telemetry so you can begin exploring your IoT data in DevicePilot.
You can book a demo at devicepilot.com
Find your token in Settings > Tokens
npm install devicepilot
const DevicePilot = require('devicepilot');
const dp = DevicePilot({
postToken: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', // Required for post requests
kpiToken: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', // Required for kpi requests
});
dp.post
: takes a telemetry record or an array of records and posts it to DevicePilotdp.kpi.getResults
: takes a KPI identifier and returns its current resultsasync function post() {
await dp
.post({
$id: 'unique-device-id', // this is used to identify your device
// any valid json body will be converted into key:value telemetry:
ledColour: 'blue',
switchedOn: true,
temperature: 20,
// an array of record objects can also be provided
})
.catch((error) => {
// an error occurred and the post was not successful.
console.log('post was not successful');
throw error;
});
console.log('posted one record successfully');
}
post();
// You can find the ID of a KPI from the Tokens page.
// See documentation for further information.
const kpiId = '12345678-abcd-1234-abcd-1234567890ab';
async function get() {
const kpiResult = await dp.kpi
.getResults(kpiId)
.catch((error) => {
// an error occurred fetching results
});
const {
error, // if provided, an error occurred when calculating the kpi
data, // data required to display a KPI result, e.g. x and y for a scatter chart
meta, // additional information about the data returned, e.g. the type of the y axis
} = kpiResult;
if (error) throw new Error(error);
console.log(JSON.stringify(data, null, 2));
}
get();
Version 2.0 introduces dp.kpi.getResults
and makes devicepilot
isomorphic (the package can now safely be used in browser and server deployments).
To achieve this we have dropped support for token configuration from the environment, and instead added the postToken
and kpiToken
to the constructor.
Version 3.0 requires node 10 or above for server environments.
For more information about using DevicePilot, check out: https://help.devicepilot.com/
Author: DevicePilot
Demo: https://www.devicepilot.com/
Source Code: https://github.com/DevicePilot/devicepilot-js
#node #nodejs #javascript