Socket
Book a DemoInstallSign in
Socket

gpio-stream

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gpio-stream

Readable and Writable GPIO Streams for use with the Raspberry Pi

1.0.17
latest
Source
npmnpm
Version published
Maintainers
1
Created
Source

GPIO Stream

GPIO Stream allows you to pipe around inputs and outputs on the Raspberry Pi using the node.js stream API. Why is this a good thing? Node streams allow you to pipe output from one stream to the input of another stream, just like unix pipes. Streams make it easy to combine small chunks of code into complex systems with very little effort.

Installing

npm install gpio-stream

A Simple Example

Let's say we want to view the state of the button from our SSH connection. Since stdout is a writable stream, we can pipe the output of the button directly to stdout.

led gif

var GpioStream = require('gpio-stream'),
    button = GpioStream.readable(17);

// pipe the button presses to stdout
button.pipe(process.stdout);

Next Steps

Now let's try a simple example of how to pipe the output of a button to an LED.

led gif

var GpioStream = require('gpio-stream'),
    button = GpioStream.readable(17),
    led = GpioStream.writable(18);

// pipe the button presses to the LED
button.pipe(led);

Going Further

What else can we do with this? How about streaming the button presses to a LED & to a web browser? Since the node.js HTTP server response is a writable stream, we can pipe the button presses to the LED, and then to the HTTP response object. Your browser can receive the presses on the fly using chunked transfer encoding. All of that with ~10 lines of code!

browser gif

var GpioStream = require('gpio-stream'),
    http = require('http'),
    button = GpioStream.readable(17),
    led = GpioStream.writable(18);

var stream = button.pipe(led);

http.createServer(function (req, res) {
  res.setHeader('Content-Type', 'text/html');
  res.write('<pre>logging button presses:\n');
  stream.pipe(res);
}).listen(8080);

License

Copyright (c) 2014 Adafruit Industries. Licensed under the MIT license.

Keywords

raspberry

FAQs

Package last updated on 12 Oct 2015

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.