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 socket.io 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 web.py 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.Beaglebone Black Web Control Using WebPy

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 192.168.7.2 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 web.py

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 web.py

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.Beaglebone Black Web Control Using WebPy schematic

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.

Due to downloading issues, please copy and paste the code from my github account

Step 4: Transferring the Python File to Your Beaglebone

You can transfer the main.py 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 main.py file in the Desktop or any other directory you choose.

 

For more detail: Beaglebone Black Web Control Using WebPy


About The Author

Ibrar Ayyub

I am an experienced technical writer holding a Master's degree in computer science from BZU Multan, Pakistan University. With a background spanning various industries, particularly in home automation and engineering, I have honed my skills in crafting clear and concise content. Proficient in leveraging infographics and diagrams, I strive to simplify complex concepts for readers. My strength lies in thorough research and presenting information in a structured and logical format.

Follow Us:
LinkedinTwitter

Leave a Comment

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

Scroll to Top