Tested on:Raspberry Pi 2; Raspberry Pi B+; Python 2.7; Raspbian pre Jessie
Prerequisites:Raspberry Pi with Raspbian Jessie and internet connection (see steps 1-7 in the Introduction)
Hardware:(3 LEDs and fitting resistors)

WebIOPi: a simple but great web api for the Raspberry Pi

WebIOPi is an absolutely great freeware web interface for the Raspberry Pi, a tribute to the developers! The setup is easy and finished in less than 30 minutes: the Raspberry Pis GPIO can be controlled with just a few lines of code over internet then.

UPDATE: Installing WebIOPi on a Raspberry Pi 2 or 3
Installing WebIOPi on a Raspberry Pi 2 or 3 requires applying this patch.

Download WebIOPi
Download and unzip WebIOPi with

Install and start WebIOPi

In the browser of the host computer, navigate to RASPI_IP:8000/webiopi with RASPI_IP being the IP address of the Raspberry Pi, login with name webiopi and password raspberry.

WebIOPi - Main Menu

WebIOPi – Main Menu

After clicking on GPIO Header, the Raspberry Pis GPIO can be accessed from the Web interface:
WebIOPi - GPIO interface

WebIOPi – GPIO interface

For example, attach a LED to BOARD pin 7(BCM 4) and GND, click the grey box left of it in the interface to make it an output and then click the number 7 to light it up.

Important: At least change the username and password in /etc/webiopi/config (under [HTTP]) before the application goes life!

Example Project
This sample project is an extension of the sample files from the WebIOPi website. Download the sample application with

Attach the LEDs to pin 11, 12 and 13 in BOARD numbering(17, 18 and 27 in BCM numbering).

Setup document directories

The new html and script directories need to be stored in WebIOPis config file to make them work. Type sudo nano /etc/webiopi/config. Below the line


. Additionally, below the line


to store the new html root directory. Then, start the example project by typing

in the terminal.

Python connecticity
Defining python functions for WebIOPi is similar to Python decorators.
In example.py, add @webiopi.macro above the function which should be called from WebIOPi

and access it from the index.html of WebIOPi with

See the great general tutorial and the tutorial on macro usage from the developer of WebIOPi, trouch, for further information.

Return data from Python
In the example project, the button Calculate calls the python macro count_a_lot and displays the return value. This happens by passing the Javascript handler function perform_calculation:

The handler function stores the returned value in the html text input textResult:

Example code
Click on Full Script to show the example script.

Click on HTML Code to show the HTML file.

Hack: use modules from a different Python version
Wrap the python function call in a system call allows using independant modules without updating them and their dependencies to python3 (e.g. pi-switch for controlling remote switches).

WARNING: using exec is dangerous.

WebIOPi Website: https://code.google.com/p/webiopi/
WebIOPi on sourceforge: http://sourceforge.net/projects/webiopi/files/
File transfer with SCP: http://www.knight-of-pi.org/scp-copy-linux-raspberry/
Angry IP Scanner usage: http://www.knight-of-pi.org/sniff-a-raspberry-angry-ip-scanner
Python wiki on decorators: https://wiki.python.org/moin/PythonDecorators
WebIOPi general tutorial: https://code.google.com/p/webiopi/wiki/Tutorial_Basis
WebIOPi macro usage tutorial: https://code.google.com/p/webiopi/wiki/Tutorial_Macros
Home automation with rc switches: http://www.knight-of-pi.org/cheap-home-automation-with-a-raspberry-pi-controlling-rc-switches-with-pi-switch/
Patch: WebIOPi for Raspberry Pi 3: http://www.knight-of-pi.org/webiopi-for-the-raspberry-pi-3/

Knight of Pi

Johannes Bergs aka Knight of Pi. Diploma in Bioinformatics, some Webdesign and Python coding then. Living in the beautiful city of Vienna.


  1. Hi, i have tried to work the code on raspberrypi3 . LED turns on which is connected to GPIO 17 using the command (sudo webiopi -d -c /etc/webiopi/config) but it just displays the code of script.py when i open it in the chrome browser..it should actually display a button instead.
    Please help me to solve this issue.

    Thank you.

    • Hi Harry,
      do not open the script text file in your browser. Just browse to RASPI_IP:8000/webiopi, then the Python code can be executed with the button.

  2. sudo webiopi -d -c /etc/webiopi/config

    This command is giving me error saying :
    socket.error:[Errno 97] Address family not supported by protocol

    During handling of the above exception, another exception occurred
    socket.error:[Errno 98] Address already in use.


  3. Hallo Sir’s
    we have the Raspberry 2B
    should we need a new version of the library of
    webiopi.js ????
    why the examples does not work
    thank you very much
    best regards Franz

    • Hi Franz,
      what doesn’t work? Can you post the error message?


Time limit is exhausted. Please reload CAPTCHA.