IoT Cookbook > Raspberry Pi > Remote GPIO

Remoting the Pi GPIOs

-- under construction --

The example shows how to expose two LEDs and a button wired to the Pi's GPIOs via WAMP so you can turn on/off the LEDs and sense the button from any other WAMP component.

Try it out

The code for the example consists of a adapter written in Python and AutobahnPython using Twisted. The adapter runs on the Pi and connects to Crossbar.io running on a network accessible from the Pi.

Comes with a frontend running in browsers. The frontend is written in JavaScript using AutobahnJS and connects to the same Crossbar.io router instance as the backend connects to. Consequently, the frontend is able to invoke the procedures exposed on the Pi and subscribe to events generated from there.

The hardware side

Write me.

The software side

The code for this can be found in the crossbarexamples GitHub repository under iotcookbook. You need to clone this (or download it as a ZIP file).

If you don't have aleady, login to your Pi and install Autobahn:

sudo pip install autobahn[twisted]

If you run a recent Raspbian, you are all set. If not, you might need to install RPi.GPIO sudo apt-get install python-dev python-rpi.gpio

Copy the backend component from your computer to the Pi:

scp gpio_backend.py pi@<IP of your Pi>:~/

and login to start the component

sudo python gpio_adapter.py --router <WebSocket URL of your Crossbar.io Router>

The backend has to run as root because it needs to access the GPIOs, which is a restricted operation.

The API

The adapter exposes these procedures

and publishes event on these topics

Using it

Write me.

Resources