Playing with my Raspberry PI and its GPIO over the weekend it occurred to me I would be able to control it in real time from a browser, using Socket.IO and pi-gpio.
Here is a link to my Github code for doing so: https://github.com/fgheorghe/jsGPIO.
The JSGPIOServer module creates an HTTP server handling Socket.IO events, producing an example HTML interface and interacting with the GPIO. The supported incoming event is write, taking in a data object – made of a pin number and a numeric value. This event sends data to your GPIO using the pi-gpio module. In return, it emits a wrote event, once writing has been successfully completed – passing in the input data, and an err event once an error occurs – passing in the input data along with a message property indicating the error reason.
The JSGPIOClient class creates a Socket.IO client emitting and receiving events from the server. Supported incoming events are wrote and err, which trigger a call to configured wroteEventHandler and errEventHandler functions. This class provides a write function used for sending a data object to the server made of a pin number and a value. The value is written to the given pin by the server.
Example client usage is available in index.html.
Example server usage is available in example-server.js.
Have a look at the README.md files for more details or read the source code comments.