Using Flask to Send Data to a Raspberry Pi

Introduction

In this tutorial, we’ll show you how to send data from cheap WiFi nodes to a Raspberry Pi over an internal WiFi network. It relies on the Flask framework for Python, which is a relatively simple-to-use method of creating a web application that can execute Python scripts.

MAIN_I

 

We’ll use a Raspberry Pi 3 and SparkFun ESP8266 Thing to demonstrate. We’re going to send a very simple signal from the Thing board to the RasPi – just a signal to turn an attached LED on or off. Hopefully, it’ll be obvious from the example how to send more complex signals and run more complex scripts upon receipt.

Required Materials

You’ll need the items on this wishlist to complete this tutorial. Substitutions can be made; a Raspberry Pi Zero W can be substituted for the Pi 3, for instance, and individual components can be sourced instead of the full starter kit.

 Raspberry Pi + Flask Tutorial SparkFun Wish List

Required Tools

No special tools are required to follow this tutorial. You will need a soldering iron, solder, and general soldering accessories.

Hardware Hookup

You’ll need to do some basic breadboarding to prepare for this tutorial. Don’t worry, we’ll walk you through all of it.

Raspberry Pi Connections

The connections for the Pi are simple: we’re just connecting one LED to GPIO pin 2. See the Fritzing diagram below for information on how to do that.

raspi_fritzing

 

ESP8266 Thing Connections

Hook up two of the buttons as seen in the Fritzing diagram below.

ThingButton_bb4

 

One of the buttons will turn the remote LED on, the other will turn it off. We’re going to assume that you’re capable of soldering the headers onto the ESP8266 Thing board yourself, but if you need some help, check out our soldering tutorial.

This is also where you’ll use the long, centered breakaway headers. A six-pin group of them inserted into the breadboard aligned with the programming pins on the Thing will give you a place to plug in the FTDI board.

Raspberry Pi Software

Let’s get down to business and program the Raspberry Pi to serve a web app that we can use for data connection. This tutorial assumes that you have some familiarity with Linux and Python to follow along.

Installing Flask

The first step is adding support for Flask to the RasPi. Python is already installed and support for using GPIO through Python, so we don’t need to worry about that.

All 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. However, we’re not going to get into how to set up and run a Pi without a monitor.

The first thing you need to do is install the Flask framework. There are a lot of additional packages that can be used with Flask, but we only need the basic package for this tutorial.

Read More Info…

Using Flask to Send Data to a Raspberry Pi

 

Scroll to Top
Scroll to Top
Read previous post:
PIXY2 IS SUPER VISION
PIXY2 IS SUPER VISION FOR ARDUINO OR RASPBERRY PI

A Raspberry Pi with a camera is nothing new. But the Pixy2 camera can interface with a variety of microcontrollers...

Close