Controlling GPIOs using a web interface
You've been writing programs and running command-line tools and utilities to get things done, because you are the Raspberry Pi Zero expert! While it isn't too hard, you don't necessarily want to write and run a program each time you want to turn on a motor or light or take a sensor reading. For this recipe, we are going to see how we can control the GPIO bus from a web page, being served by a web server on your Raspberry Pi Zero.
Getting ready
For this recipe, we will continue using Python, but with a new library called Flask. Flask is a micro-framework for rendering Python programs into web pages, and it will work perfectly for creating a web-based GPIO controller. If you already have python
and pip
updated and configured, the command should be as simple as the following:
sudo pip install flask
After that, we jump right into coding!
How to do it...
In your
ch5
directory, create a new directory called templates with themkdir
command:mkdir /home/pi/share...