Introduction: Beaglebone Black Web Control Using WebPy

Ever wanted to create a way to control your garage door using your phone maybe collect data and view it from your laptop. There is a single board computer called the Beaglebone Black which is an extremely powerful device that allows you to control its GPIO pins in order to interact with real world items such as motors, LED's, Lamps, etc. The Beaglebone is just like a raspberry pi board but much more powerful. The Beaglebone community is not as huge as the raspberry pi's so be warned for the lack of tutorials.

As I was searching around the internet for a solution to control my Beaglebone Black from my laptop using a web page, many tutorials popped up using the Beaglebone's bonescript library and the library using the cloud 9 ide. As I followed tutorials and looked at peoples code I grew frustrated due to the fact that the cloud 9 ide kept crashing, my lack of understanding of javascript and also the lack of flexibility of each tutorial (every tutorial forced you to use a predefined amount of GPIO's). I was familiar with python and my friend introduced me to which is a great web framework used to develop web apps. I also used Adafruit's Beaglebone Black GPIO library to control the individual pins of the Beaglebone Black.

What you will need:

  • A computer
  • SSH terminal such as PuTTY or use SSH on the terminal(For Mac's and Linux, Windows does not have built in SSH)
  • A Beaglebone Black connected to the computer via USB
  • An internet connection to the Beaglebone Black
  • (optional) A SFTP client

Step 1: Install the Required Python Libraries

We need to install two libraries that are not standard modules in python 2.7. The libraries are the Adafruit BBIO and WebPy libraries. We need to access the Beaglebone using SSH. I decided to use the PuTTy terminal and access it using the IP address of the beaglebone, mine is yours can be found on the beaglebone start.html. If you are using Angstrom type in:

  • opkg update && opkg install python-pip python-setuptools python-smbus
  • pip install Adafruit_BBIO
  • pip install

If you are using Debian or Ubuntu:

  • sudo apt-get update
  • sudo apt-get install build-essential python-dev python-setuptools python-pip python-smbus -y
  • pip install Adafruit_BBIO
  • pip install

To test if the libraries are installed properly type in:

  • python
  • import web
  • import Adafruit_BBIO.GPIO

If no errors occur on the python console then you have installed the libraries properly and we are ready to code.

Step 2: The Python Code

The python code is fairly easy to understand if you are familiar with using python, if you are a beginner to programming you might have some trouble understanding parts of the code.

The documentation of the 2 libraries can be found here:

I have written code and commented it so you to understand and tinker with it.


Step 3: Creating the Web Page

If you the python code I attached, you can see me talking about GET request. A GET request is basically a way for a webpage to communicate with a server. In order to add, delete and switch the outputs we are using Jquery to do some basic get requests. I have attached an html page that does just that and I have also commented the code for your convenience.

The control.html file is here view-source:

Step 4: Transferring the Python File to Your Beaglebone

You can transfer the file via command line but to transfer files easily I am going to use WinSCP(you can use any sftp client) which you can download here. There is Cyberduck for mac users but since I am a PC user I do not know which one is the best so you have to google it. The process is simple just drag the file in the Desktop or any other directory you choose.

Step 5: Running the Server

Running the server is easy just use SSH using PuTTY or your terminal and change your directory to the directory. Type in:

  • python 1234

Now what we just did is ask python to run the file at port 1234

Step 6: You Have Control!

Now go to the control.html file and open with google chrome or any other browser you use, you will have a web page with 2 text boxes and 3 buttons. The pin number text box asks for the pin number like P8_10 or P8_29, etc. You need to have the name filled out in order to use the delete and switch buttons. Now that you have web control you can use this example in order to create a more advanced panel. Maybe use database capabilities to use your Beaglebone Black as a data logger or use it for home automation, the possibilities are endless. If you like this instructable then please vote for this project on the coded creations contest and also favourite this project. Thanks for reading this instructable and keep on hacking! :)

Coded Creations

Participated in the
Coded Creations