This is a simple Flask example on a Orange Pi Zero board. Flask is a Python-based web framework that offers full control. For controlling GPIO we use orangepi_PC_gpio_pyH3 Python library.
Install FlaskTo be able to run this simple example you ned to install Flask in your Armbian
:
pip install -r requirements.txt
ApplicationFirst we need to create Flask application:
from flask import Flask
app = Flask(__name__)
Than we need to configure GPIO:
from pyA20.gpio import gpio
from pyA20.gpio import port
led = port.PA12
gpio.init()
gpio.setcfg(led, gpio.OUTPUT)
After that we define two handles:
@app.route('/hello')
def hello():
gpio.output(led, 1)
return 'Hello Orange Pi Zero!'
@app.route('/bye')
def bye():
gpio.output(led, 0)
return 'Bye Bye!'
And finally we start Flask application:
app.run(host='0.0.0.0', port=80)
To be able to access it in you local network use host=0.0.0.0
. For the application to be able to bind to 80 port and to access GPIO you need to run it as a sudoer.
sudo python run.py
TestingTo test this application we use nice Android HTTP Request Widget. It has a lot of Here is how you configure it:
As a result you have a nice and simple control panel on you Android home screen:
Comments
Please log in or sign up to comment.