I need help with writing code on python using web servers. I want to know when a button is clicked how to tell a LED to be turned on and to relay that information back to the web server displaying if the LED is on or off. Here is my current code. import web
global status
status = [0]
render = web.template.render('web/')
urls = ( '/', 'hello')
app = web.application(urls, globals(), True)
class hello:
def GET(self):
getInput = web.input(turn="")
command = str(getInput.turn)
return """<html>
<head>
<title>Control Centre </title>
</head>
<body>
<font size="20"> </font>
<p> <font size="20"> <b>Control Centre</b> </font> </p>
</body>
<p> <button type="submit1">LED 1</button> </p>
<p> <button type="submit2">LED 2</button> </p>
<p> <button type="submit3">LED 3</button> </p>
<p> <button type="submit4">LED 4</button> </p>
<p> <button type="submit5">LED 5</button> </p>
<p> <button type="submit6">LED 6</button> </p>
<p> <button type="submit7">BUZZER</button> </p>
</html>"""
if command == "1":
if status[0] == 0:
status[0] = 1
GPIO.output(4, GPIO.HIGH)
print 'LED 1 ON'
return render.index(status)
elif status[0] == 1:
status[0] = 0
GPIO.output(4, GPIO.LOW)
print 'LED 1 OFF'
return render.index(status)
else:
print 'error'
return render.index(status)
return render.index(status)
if __name__ == "__main__":
app.run()