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