npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

particle-processing-rk

v0.0.5

Published

Helper for using Particle IoT devices with OpenProcessing p5.js

Downloads

2

Readme

particle-processing-rk

Helper for using Particle IoT devices with OpenProcessing p5.js

OpenProcessing is often used for graphics programming, but you can also use it to interact with your Particle IoT devices over the cloud!

One problem with using the Particle API (via particle-api-js) is that you need a Particle access token. Pasting the access token into your source code is bad practice. Also, with OpenProcessing is that sketches are public, except for paid tiers, and that means anyone who views your sketch has full control of your Particle account. Not good!

The helper makes it easy to prompt for username, password, and if enabled, MFA token. It then obtains a time-limited access token (good for 4 hours maximum), and stores it in browser local storage. If you refresh your sketch during the token life, you don't need to log in again, making the process seamless.

If you're done before the time limit, it also places a Logout button at the top of the page which invalidates your access token and removes it from browser local storage. This is useful if you are using a shared computer, to make sure the next user won't have access to your account.

The library provides convenient helpers for selecting a device from the logged in user's Particle account, and doing Particle primitive functions such as Particle.function, Particle,variable, and Particle.publish so you can interact with your Particle device over the cloud easily.

It also provides access to the full particle-api-js in case you want to use more advanced features.

This library assumes you are using OpenProcessing in p5js mode.

Function Publish Demo

This is a demo of using login, device selector, function, publish, and variable features.

  • Flash your Particle device with the code in firmware/function-publish.cpp.
  • Create a new sketch from the source in sketches/function-publish.js.
  • Add the particle-processing-rk library to your sketch.
  • Run it!

Helper API

Adding the particle-processing-rk.js library in your Sketch automatically adds a new global object, particleHelper.

Call particleHelper.setup() from your setup(). This will prompt for login, if necessary.

Instead of setting up UI elements in setup() you should move them to afterLoggedIn(). This is because during setup the helper may UI elements for logging in, then remove them using the ps5js function removeElements(). Thus if you add non-canvas elements from setup() they could disappear after the user logs in.

If the afterLoggedIn() function is present in your sketch, it will be called so you can do other things.

function setup() {
    createCanvas(windowWidth, windowHeight);
    background('#202020');

    // Add the particle-processing-rk.js to add the particleHelper global object
    particleHelper.setup();
}

// The afterLoggedIn function(), if present, is called after the user has logged in
function afterLoggedIn() {
    console.log('logged in!');
}

You can customize behavior by updating properties in the particleHelper object before calling particleHelper.setup().

Some values you may want to update:

  • tokenDuration is the lifetime for new access tokens in seconds. The default is 4 * 3600 (4 hours).

  • foregroundColor is the color to use for text. The default is #e0e0e0. If you are using a white background you will probably want to change this.

  • top and left specify the location of login controls. By default, this is the top left of the window (5, 5) but you can position the controls elsewhere if desired.

Release Notes

0.0.5 (2023-07-24)

  • Initial version