Super Simple BeagleBone Web Interface!
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 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:
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:
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.
Hi Alexander, that’s pretty neat. We have a small community over at Arm-Hq(forum.arm-hq.com). If you have some time, be sure to join us to share your beaglebone projects.
(http://forum.arm-hq.com/index.php?/forum/16-beagleboard-and-beaglebone/)
PyBBIO and BBIO Server are awesome!!! Thanks for creating them! I have been using this library in a leadacid UPS/web enabled charge controller. It is also helping me learn Python! I do get some wackiness on ADC pins sometimes it seems like I am reading the same pin vs a different pin from time to time. I really don’t know how to explain the anomaly. I also tried the new A6a angstrom and it seems to mess up the http socket blocking stuff. ie when you access the BBIOServer it is dog slow then it just freaks out and spits a bunch of socket error stuff. Keep up the amazing work with PyBBIO cant wait for i2c 😀
Hi, I’m begginer in webservers and this stuff. I was trying to use your example but It shows some mistakes:
from bbio import *
File “/usr/lib/python2.7/site-packages/bbio/__init__.py”, line 4, in
from bbio import *
File “/usr/lib/python2.7/site-packages/bbio/bbio.py”, line 45, in
from config import *
File “/usr/lib/python2.7/site-packages/bbio/config.py”, line 416, in
for i in PWM_PINS.keys())
File “/usr/lib/python2.7/site-packages/bbio/config.py”, line 416, in
for i in PWM_PINS.keys())
IOError: [Errno 2] No such file or directory: ‘/sys/class/pwm/ehrpwm.1:1/request’
I’ll appreciate your help
I have updated PyBBIO but I have even two mistakes:
File “server.py”, line 3, in
from bbio import *
File “/home/root/PyBBIO/examples/bbio.py”, line 45, in
from config import *
ImportError: No module named config
I’ll appreciate your help
The first error looks like it’s due to the fact that you’re running the 3.8 kernel (BeagleBone Black I assume), which PyBBIO does not yet support. It should work soon though, so keep an eye on the Github page.
The second error looks like it was caused by having the bbio.py file in the examples directory, where it shouldn’t be. When a Python program tries to import a module, the current directory is checked first. You’re importing the bbio.py that’s in the PyBBIO/examples/ directory, but it thinks it is in the system directory to which it gets installed, and it is unable to find the files it needs. You must have moved or copied it there from the PyBBIO/bbio/ directory.
Does this work with ubuntu?
Yes, it should work with any Ubuntu BeagleBone image with the 3.2 kernel (3.8 support coming).
Good morning 🙂
Regarding PyBBIO:
I have servertest.py running.
ONE:
root@beaglebone:/home/PyBBIO/examples# python blink.py
gives:
IOError: [Errno 2] No such file or directory: ‘/sys/class/gpio/gpio55/direction’
TWO:
I cannot see where to specify your mobile.css template for a phone.
I am using a BBB with 3.8 kernel
Thnak you for your time.
blink.py fails right now because there’s an issue with the way PyBBIO is handling the USR LEDs. That will be fixed soon.
You can see where to specify the mobile stylesheet in the example program here: https://github.com/alexanderhiam/PyBBIO/blob/master/examples/BBIOServer_mobile_test.py#L48
The USR LEDs should be working now.
Hi,
This looks great. I’m thinking about using something like this to control a small electrical heater. Do you think it would be possible to use this to turn on and off a PWM connection to a relay?
Absolutely, you’d just need a callback function that toggles the heater and a button to call it. Check out the documentation link above, it includes a tutorial.
Hello Alexander Hiam,
Thanks a lot for this easy web-interface. I have a question.
1. How did you free the port for hosting your web-server?
generally, cloud9 ide , Boneservice will be running right? After googling I came to know that we need to disable the services.
I have BB Black. I want to develop a simple web server to toggle the leds.
Please do guide me.. thanks in advace.
Regards
vish
No need to stop Cloud9, it’s running on port 3000 and BBIOServer runs on port 8000 by default.
Hi Alexander,
is there a way to change this to blinking external leds, instead of the on-board leds using your library? Thank you!
Certainly, just use any of the GPIO pins instead of USR3: https://github.com/alexanderhiam/PyBBIO/wiki/Digital-IO#available-gpio-pins