Giter VIP home page Giter VIP logo

sensorpush's Introduction

sensorpush

This is an npm module for the new SensorPush API. It is lightweight; this module requires ZERO external modules, especially no big-ass https request module.

It is unofficial and I'm happy to hand ownership over to the sensorpush.com team, or another engineer they approve of.

SensorPush

Installation

npm install sensorpush

A quick example

const sensorpush = require('sensorpush');

let credentials = {
  email: "[email protected]",
  password: "y0urP@ssword-on-sensorpush"
};

// step 1: get an authorization code
sensorpush.api.oauth.authorize(credentials, function (err1, res1) {

// step 2: get an access token
  sensorpush.api.oauth.accesstoken({ authorization: res1.authorization }, function (err2, res2) {

    let accesstoken = res2.accesstoken;

    // steps 3-5: get data, using the access token
    sensorpush.api.devices.sensors({ accesstoken: accesstoken }, function (err3, res3) {
      console.log("Sensor response:", res3);
    });

    sensorpush.api.devices.gateways({ accesstoken: accesstoken }, function (err4, res4) {
      console.log("Gateways response:", res4);
    });

    // get any readings from the last 10 mins
    let startTime = new Date(Date.now() - 60 * 1000 * 10);
    sensorpush.api.samples({ limit: 10, startTime: startTime, accesstoken: accesstoken }, function (err5, res5) {
      console.log("Samples response:", res5);
    });
  });
});

Promises?

If you're looking for a version of this that uses Promises, I'll take a PR that wraps each of the API functions and exposes in a sensorpush.promise object. So for example, a user of this module could call either:

sensorpush.api.samples(opts, cb);

Or

sensorpush.promise.samples(opts).then(/* etc. */)

This should be in as plain JS and require no external modules for either inclusion or building.

sensorpush's People

Contributors

malgorithms avatar tmwllc avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.