From charlesreid1

Running Web Server on Raspberry Pi

If you're running a web server on Raspberry Pi, you'll probably want to run on port 80. However, Raspberry Pis sometimes have a problem when installing Python packages into /usr/local/lib, so you have to install them into a custom directory. This creates a problem when trying to import the package as root, because root python won't be able to find it (won't have the $PYTHONPATH variable set correctly).

To get around this, you can bind to port 80 without being root by following these instructions:

http://stackoverflow.com/questions/413807/is-there-a-way-for-non-root-processes-to-bind-to-privileged-ports-1024-on-l

http://www.wensley.org.uk/info#setpcaps

Flask

Flask is an excellent lightweight web server in Python. Flask makes it easy to create an API for requesting data and passing JSON between Python (which is a powerful language that can control all kinds of things on the Raspberry Pi) and Javascript (which provides a nice user front-end via a web interface).

For an example of how you might do this, see my Dymouse project on Github: http://github.com/charlesreid1/dymouse

The concept is to use a computer with a Flask server, with one side connected to a sensor, and the other side interacting with the user. Python libraries can be used to interface with USB devices (and get the weight reading from the postage scale). This information can be obtained by Flask, which turns it into JSON to be returned when the user requests it. This is linked to a REST-ful URL on the web server.

On the user side, the user interacts with an HTML web page controlled by Javascript. It is the Javascript code that decides to make a JSON request to the REST-ful URL. It makes the request, based on user interaction or some other criteria, then parses the reading and adds it to the page in an appropriate manner.



Flags