from wsgiref.simple_server import make_server from urlparse import parse_qsl import smbus bus = smbus.SMBus(1) address = 0x04 def writeNumber(value): bus.write_byte(address, value) # bus.write_byte_data(address, 0, value) return -1 html = """

""" def application(environ, start_response): # Returns a dictionary containing lists as values. d = parse_qsl(environ['QUERY_STRING']) try: if (d[0][0]=="led1"): print "led1" writeNumber(1) if (d[0][0]=="led2"): print "led2" writeNumber(2) if (d[0][0]=="led3"): print "led3" writeNumber(3) if (d[0][0]=="led4"): print "led4" writeNumber(4) except IndexError: pass response_body = html status = '200 OK' # Now content type is text/html response_headers = [('Content-Type', 'text/html'), ('Content-Length', str(len(response_body)))] start_response(status, response_headers) return [response_body] httpd = make_server('', 888, application) # Now it is serve_forever() in instead of handle_request(). # In Windows you can kill it in the Task Manager (python.exe). # In Linux a Ctrl-C will do it. httpd.serve_forever()