Control your Raspberry PI GPIO in Real Time via the Browser using NodeJS, Socket.IO and pi-gpio

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.

3 thoughts on “Control your Raspberry PI GPIO in Real Time via the Browser using NodeJS, Socket.IO and pi-gpio”

  1. Thanks for this framework – I have been looking to accomplish something very similar with my new Pi.
    I setup pi-gpio, cloned the git and have it serving the page correctly, I also updated index.html to point to my Pi; however, when I enter a gpio pin and click on or off or even hover, no messages are displayed and no action is being taken.

    Are there additional configuration/steps required to have socket.io working correctly?

    Thanks again!

    1. No worries. Can you please show me any logs or output messages, either from your browser’s console, or the node server?

      1. Sorry for the late reply – not sure what’s wrong. Can you please reply with Chrome’s console output, when opening the page? There may be a JavaScript error.

Leave a Reply

Your email address will not be published. Required fields are marked *