

When some http request comes in with a path of tup(2, GPIO.OUT) # Set GPIO2 as an outputĪpp = Flask(_name_) # Create an instance of flask called # This is our default handler, if no path is given # GPIO pins exported for use via command line twarnings(False) # Turn off warnings that may crop up if you have the # given in most documentation of the Pi header tmode(GPIO.BCM) # Sets up the RPi lib to use the Broadcom pin mappings Open that file in your favorite text editor (the Pi has vi, nano, and a textpad). This is the file that we're going to put our code into. The next step is to create a blank Python file in the directory called "app.py". These commands will create the directory and ensure that you're working inside that directory. Next, we're going to create the directory within which the app will run. There are a lot of additional packages that can be used with Flask, but we only need the basic package for this tutorial. The first thing you need to do is install the Flask framework. However, we're not going to get into how to set up and run a Pi without a monitor. Python is already installed and support for using GPIO through Python, so we don't need to worry about that.Īll of these commands can be run either on a serial terminal opened on the Raspberry Pi directly with the Pi hooked up to a monitor, or remotely with a Pi via an SSH connection. The first step is adding support for Flask to the RasPi. This tutorial assumes that you have some familiarity with Linux and Python to follow along. Let's get down to business and program the Raspberry Pi to serve a web app that we can use for data connection.
