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_response(200) self.send_header("Content-type", "text/html") self.end_headers() self.wfile.write("<html>my web content and javascript here</html>)
elsif url eq "/myajaxhandler":
# get your LED state from URL params self.send_response(200) GPIO.setStuffHere()
else:
self.send_response(403) # forbidden self.send_header("Content-type", "text/plain") self.end_headers() self.wfile.write("Forbidden from " + path)
if __name__ == "__main__":
print('Starting HTTP server on port 8080") server = HTTPServer(("", 8080), Handler) server.serve_forever()
On 11/10/17 18:28, steve-ALUG@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@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!