I've been working for a while now on PyBBIO, my Python library for BeagleBone hardware expansion. It's got some neat features, but my favorite so far is the BBIOServer library, which makes creating web interfaces to PyBBIO incredibly simple.

BBIOServer provides two things: a web server class called BBIOServer, and a HTML page class called Page. To use it you create a Page instance for every page you want your web interface to have, add content to them through the Page methods, then pass them all to the start() method of a BBIOServer instance, and it will create the pages complete with a sidebar to navigate between them, then start the server on the default port of 8000, or whatever port you have specified.

To create a single page with a button that toggles the USR3 on-board LED, as well as a monitor of its current state, would look something like this:

from bbio import *
from BBIOServer import *

server = BBIOServer()

def setup():
  page = Page("Server test")
  page.add_text("This is a test of the BBIOServer library.")
  page.add_button(lambda: toggle(USR3), "Toggle USR3", newline=True)
  page.add_monitor(lambda: pinState(USR3), "Current state:")
  server.start(page)
  stop()

def loop():
  pass

run(setup, loop)

And if you run that and point your browser to http://your_beaglebone_ip_address:8000 you should see something like this:

bbioserver

In this case the Page instance uses the default stylesheet, but you can also point to other stylesheets in the PyBBIO/libraries/BBIOServer/src/ directory. Besides the default stylesheet, BBIOServer includes a stylesheet that makes the pages get along well with mobile browsers. If you replace page = Page("Server test") in the above code with page = Page("Server test", stylesheet="mobile.css"), then head to http://your_beaglebone_ip_address:8000 on your phone, you should see something like this:

bbioserver_mobile

Here's a quick video of one of the BBIOServer examples included in PyBBIO (see the code here):

Be sure to check out the BBIOServer documentation.

Share on RedditShare on LinkedInShare on FacebookTweet about this on TwitterShare on Google+