Socket
Book a DemoInstallSign in
Socket

particle-blast

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

particle-blast

middleware to update your particle device

1.0.0
latest
npmnpm
Version published
Maintainers
1
Created
Source

Particle-Blast

Middleware to conveniently blast your Particle device with request details.

Usage

First, create a new instance and pass in device credentials

let ParticleBlast = require('particle-blast');

let blast = new ParticleBlast({
  'device': [your device id],
  'token': [your user token]
});

Calling the .fire() method of the instance will return an Express/Connect compatible middlware function.

let express = require('express');
let app = express();

// using the blast instance we created previously
app.use(blast.fire([deviceFunction], [parseFunction], [callback]))

// ... continue configuring express app ...

#fire([deviceFunction], [parseFunction], [callback])

Returns middleware function.

Arguments:

deviceFunction - String, name of registered Particle Function you wish to invoke.

parseFunction - Function, takes the request object as an argument. Use this to get whatever data you need from the request object. This will return the string data your registered Particle Function may require.

callback - Function, callback to execute after your device returns an error and/or data.

let parseReq = function (req) {
  return req.ip;
};

// arguments as passed by Particle Cloud
let callback = function (err, response, data) {
  if(err) {
   console.log('ERROR: ', err);
  }
  conosle.log('Returned by Particle Cloud: ', data);
};

app.use(blast.fire('ipToLCD', parseReq, callback));

A single blast instance can be reused to run multiple registered functions if multiple functions are registered to the same device.

  app.use(blast.fire('fn1', parseOne, callbackOne));
  app.use(blast.fire('fn2', parseTwo, callbackTwo));

Keywords

middleware

FAQs

Package last updated on 09 Jan 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.