Skip to content

Node library for https://github.com/teco-kit/explorer. Can be used to upload datasets as whole or incrementally.

License

Notifications You must be signed in to change notification settings

teco-kit/explorer-node

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

explorer-node

Node library for https://github.com/teco-kit/explorer. Can be used to upload datasets as whole or incrementally.

Tests

How to use

Installation

The library can be installed from npm

npm i explorer-node

Upload datasets as a whole

const sendDataset = require("explorer-node").sendDataset;

sendDataset(
  (url = "explorerBackendUrl"),
  (key = "deviceApiKey"),
  (dataset = dataset)
)
  .then((msg) =>
    // Handle success
    console.log(msg)
  )
  .catch((err) =>
    // Handle error
    console.log(err)
  );

Upload datasets in increments

Upload datasets in increments with custom timestamps
const datasetCollector = require("explorer-node").datasetCollector;

// Generate collector function
const collector = await datasetCollector(
  (url = "explorerBackendUrl"),
  (key = "deviceApiKey"),
  (name = "datasetName"),
  (useDeviceTime = false) // true if you want to use the time of the device, false if you want to provide your own timestamps
);
if (collector.error) {
  // Error occurred, cannot use the collector as a function to upload datasetincrements
  console.log(collector.error);
  return;
}

try {
  // time should be a unix timestamp
  collector.addDataPoint(
    (time = 1618760114000),
    (sensorName = "sensorName"),
    (value = 1.23)
  );

  // Tells the libarary that all data has been recorded.
  // Uploads all remaining datapoints to the server
  collector.onComplete();
} catch (e) {
  console.log(e);
}
Upload datasets in increments with timestamps from the device
const datasetCollector = require("explorer-node").datasetCollector;

// Generate collector function
const collector = await datasetCollector(
  (url = "explorerBackendUrl"),
  (key = "deviceApiKey"),
  (name = "datasetName"),
  (useDeviceTime = true) // The datapoint at which addDataPoint is called will be used.
);
if (collector.error) {
  // Error occurred, cannot use the collector as a function to upload datasetincrements
  console.log(collector.error);
  return;
}

try {
  // No longer necessary to provide the time here
  collector.addDataPoint((sensorName = "sensorName"), (value = 1.23));

  // Tells the libarary that all data has been recorded.
  // Uploads all remaining datapoints to the server
  collector.onComplete();
} catch (e) {
  console.log(e);
}

About

Node library for https://github.com/teco-kit/explorer. Can be used to upload datasets as whole or incrementally.

Resources

License

Stars

Watchers

Forks