[ALUG] Controlling a Raspberry PI I/O pins via web App

Simon Ransome simon at nosher.net
Thu Oct 12 10:04:07 BST 2017

Hi Steve,

It's pretty trivial to set up a web server in Python directly, so you 
could knock up a very simple server which both serves your web page and 
responds to JavaScript/Ajax requests from it. Something like this 
(slightly pseudo-code)...

#!/usr/bin/env python

import urlparse
from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer

class Handler(BaseHTTPRequestHandler):

     """ A simple Python web server """

     def do_GET(self):

         """Handle HTTP Get requests"""

         urlpath = urlparse.urlparse(self.path)
         url = urlpath.path

         if url eq "/myledwebpage.html"

             self.send_header("Content-type", "text/html")
             self.wfile.write("<html>my web content and javascript 

	elsif url eq "/myajaxhandler":

	    # get your LED state from URL params	


             self.send_response(403) # forbidden
             self.send_header("Content-type", "text/plain")
             self.wfile.write("Forbidden from " + path)

if __name__ == "__main__":

     print('Starting HTTP server on port 8080")
     server = HTTPServer(("", 8080), Handler)

On 11/10/17 18:28, steve-ALUG at hst.me.uk wrote:
> Can any Raspberry Pi users out there or web people help? I Want to use 
> webpage to control Neopixels plugged into a Raspberry Pi.  The webpage 
> will have slider controls for R, G, B & overall brightness. I was 
> initially thinking of using cgi-bin scripts using python, but I want the 
> colour to change as the slider moves so I don't know if that would be 
> responsive enough.
> Reading around, there seem to be many python-based solutions* so I could 
> use cgi scripts, web sockets, webpy, flask, danjo or others. Anyone got 
> a recommendation of which way to go. Lightweight and no security will do.
> *I want to use python if possible as that's what I'm most familiar with 
> ATM, with a bit of Javascript as required.
> Any advice appreciated.
> Steve
> _______________________________________________
> main at lists.alug.org.uk
> http://www.alug.org.uk/
> https://lists.alug.org.uk/mailman/listinfo/main
> Unsubscribe?  See message headers or the web site above!

More information about the main mailing list