Kevin Sidwar

Software Engineer + Hardware Enthusiast

604

--

Add a Web Interface with Bottle

As a continuation of the class project I want to add a few things. I'll be using the base class project where it left off at the end of the class and adding the following:

  • Relay interface to be able to turn on AC devices like lights and motors
  • Web interface using the Bottle framework so I can control the hardware remotely

Step 1 - Add Bottle

The first thing we need to do is get the bottle framework installed and working. Then we'll worry about hooking into the hardware pieces. To install bottle I just did:

sudo apt-get install python-bottle

I tried using pip to install bottle but ran into issues on the Raspberry Pi so I recommend using apt-get install instead.

Step 2 - PiHardware Class

To make working with the hardware easier I moved a lot of my class project code into a separate module named hardware.py and created the PiHardware class which simplifies interacting with the hardware we built in the class project. With the PiHardware class we can do things like this:

Step 3 - Create Server

There are two pieces to adding a web interface to the hardware: server and client. Bottle serves as the server running on the Raspberry Pi so I created a very simple bottle implementation that defines a few routes to allow me to turn the LED on and off and get a temperature reading using the PiHardware class I created in Step 2. These are just simple GET and POST calls.

Step 4 - Create Client App

I created a simple AngularJS application to serve as the client-side piece and styled the whole thing with Twitter Bootstrap. Here's the first working iteration. The live feed view is from the Raspberry Pi Camera module I have connected (more on this later). With this web UI I can turn the LED on and off and get a temperature reading. The graph is just a placeholder for now.

Source Code

It's still very rough and needs some work still but I've posted the code for what I have so far on Github and you can check it out there.

pi_ponics on Github

Comments

Please sign in or sign up to comment.