Raspberry Pi - Web Server and API
This Flask code snippet is intended to turn GPIO pin 18 ON or OFF via web requests:
What is the error in this code?
from flask import Flask
import RPi.GPIO as GPIO
app = Flask(__name__)
GPIO.setmode(GPIO.BCM)
GPIO.setup(18, GPIO.OUT)
@app.route('/pin18/')
def control_pin(state):
if state = 'on':
GPIO.output(18, GPIO.HIGH)
return 'Pin 18 ON'
elif state == 'off':
GPIO.output(18, GPIO.LOW)
return 'Pin 18 OFF'
else:
return 'Invalid' What is the error in this code?
