I'm newbie for raspberry pi and python coding. I'm working on a school project. I've already looked for some tutorials and examples but maybe I'm missing something. I want to build a web server based gpio controller. I'm using flask for this. For going into this, I've started with this example. Just turning on and off the led by refreshing the page.
So the problem is, I can't see the response value on the web server side. It's turning on and off the led. But I want to see the situation online. But I just couldn't. I'm getting and internal server error. I'm giving the python and html codes. Can you help me with solving the problem.
from flask import Flask
from flask import render_template
import RPi.GPIO as GPIO
app=Flask(__name__)
GPIO.setmode(GPIO.BCM)
GPIO.setup(4, GPIO.OUT)
GPIO.output(4,1)
status=GPIO.HIGH
@app.route('/')
def readPin():
global status
global response
try:
if status==GPIO.LOW:
status=GPIO.HIGH
print('ON')
response="Pin is high"
else:
status=GPIO.LOW
print('OFF')
response="Pin is low"
except:
response="Error reading pin"
GPIO.output(4, status)
templateData= {
'title' : 'Status of Pin' + status,
'response' : response
}
return render_template('pin.html', **templateData)
if __name__=="__main__":
app.run('192.168.2.5')
And basically just this line is on my html page.
<h1>{{response}}</h1>
I think "response" doesn't get a value. What's wrong on this?