RaspberryPi/Web Server: Difference between revisions
From charlesreid1
(Created page with "=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 w...") |
No edit summary |
||
| Line 18: | Line 18: | ||
[[Category: | [[Category:Raspberry Pi]] | ||
[[Category:Web Server]] | |||
[[Category:Python]] | |||
Revision as of 23:47, 27 July 2015
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://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
This uses a Raspberry and a Flask script to create an API for a USB postage scale. Python provides a means for grabbing the weight reading from the postage scale; Flask turns it into JSON; and Javascript turns the JSON into HTML text/plots.