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.
var GpioStream = button = GpioStream; // pipe the button presses to stdoutbutton;
Next Steps
Now let's try a simple example of how to pipe the output of a button to an LED.
var GpioStream = button = GpioStream led = GpioStream; // pipe the button presses to the LEDbutton;
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!
var GpioStream = http = button = GpioStream led = GpioStream; var stream = button; http;
License
Copyright (c) 2014 Adafruit Industries. Licensed under the MIT license.