Raspberry Pi Full Stack Raspbian

A whirlwind tour of full-stack web application development on the Raspberry Pi

Last updated 2022-01-10 | 4.7

- Setup the minimal Raspbian Lite operating system to the RPi.
- Learn how to work in headless mode
- Learn to install and use the a Python virtual environment.

What you'll learn

Setup the minimal Raspbian Lite operating system to the RPi.
Learn how to work in headless mode
Learn to install and use the a Python virtual environment.
Install and use Flask
a Python-based web micro-framework
Install and use uWSGI as the application server for Flask
Install and use Nginx light-weight web server
Setup systemd to automatically start your application
Use the RPi GPIOs as digital input and outputs
Use a DHT22 humidity and temperature sensor
Install and use the SQLite database
Use the Google Chart API to create visual representations of the sensor data
Use JQuery to add interactivity to web pages
Use Plotly for graphical analysis of sensor data
Assign a static IP address to your Raspberry Pi
Expose your application to the Internet
and access it from anywhere

* Requirements

* A Raspberry Pi 4
* 3
* 2
* model B
* A Windows
* Mac or Linux computer
* A DHT22 sensor
* An 5mm LED
* A pushbutton
* A breadboard and jumper wires
* Access to the Internet
* (Check hardware requirements in a free lecture in the first section of the course)

Description

  • Setup the minimal Raspbian Lite operating system to the RPi.
  • Learn how to work in headless mode
  • Learn to install and use the a Python virtual environment.
  • Install and use Flask, a Python-based web micro-framework
  • Install and use uWSGI as the application server for Flask
  • Install and use Nginx light-weight web server
  • Setup systemd to automatically start your application
  • Use the RPi GPIOs as digital input and outputs
  • Use a DHT22 humidity and temperature sensor
  • Install and use the SQLite database
  • Use the Google Chart API to create visual representations of the sensor data
  • Use JQuery to add interactivity to web pages
  • Use Plotly for graphical analysis of sensor data
  • Assign a static IP address to your Raspberry Pi
  • Expose your application to the Internet, and access it from anywhere

Course content

14 sections • 92 lectures

0010 - What is this course about Preview 11:40

0030 - Parts you will need Preview 04:50

0050 - How to get help Preview 05:49

0060 - Code repository Preview 04:16

0110 - Raspberry Pi 3 specs and features Preview 03:28

0111 - Raspberry Pi 4 specs and features Preview 07:44

0120 - Raspberry Pi models Preview 09:17

0130a - Raspberry Pi vs Arduino high level comparison Preview 12:35

0130b - Raspberry Pi vs Arduino comparing the boards Preview 05:32

0160 - Operating systems for the Raspberry Pi Preview 08:40

0165 - Headless vs GUI Preview 06:54

0170 - Download and Install Raspbian Lite using Etcher Preview 06:05

0180 - How to enable SSH and configure Wifi in headless mode Preview 05:45

0190a - Boot for the first time and basic configuration Preview 02:33

0190b - Connect for the first time using Mac OS Preview 07:15

0190c - Boot for the first time and connection using Windows Preview 02:32

0210a - Working as the "root" user Preview 04:38

0210b - How to enable the "root" user for logging on with SSH Preview 05:18

0220a - Backup an SD card (Mac OS) Preview 07:53

0220b - Restore an SD card (Mac OS) Preview 05:47

0220c - Backup an SD card (Windows) Preview 07:11

0220d - Restore an SD card (Windows) Preview 05:30

0250 - The Rapsberry Pi GPIO header and numbering system Preview 10:22

0260a - A taste of Python on the Command Line Interpreter Preview 10:45

0260b - A taste of Python on the Command Line Interpreter Functions Preview 08:30

0270a - A taste of Python with a simple program Preview 14:37

0280 - Wire a simple circuit Preview 08:38

0290a - Install the Python installer program pip Preview 02:08

0290b - Manipulate an LED using rpi.gpio Preview 05:12

0300 - Read a button Preview 04:50

0305 - Control an LED with a button Preview 01:33

Please read before you continue: DHT22 library update Preview 00:39

Please note that the DHT22 library that I discuss in the next two lectures has been superseded by a new one.

The new library is part of Adafruit's CircuptPython project.

I recommend that you use the new library instead of the one I show in the video.

If you have already installed the old library and it works (like it does in my three instances of the RPi Full Stack that I am running), then you don't need to replace it with the new. The old library still works!

However, if you are working on a new instance of the Full Stack application, the old DHT22 library is unlikely to work for you due to dependency issues.

I will be replacing this video with a new one. In the mean time, please download the PDF document that contains a chapter of the Raspberry Pi Full Stack ebook with instructions on how to install and use the new DHT22 library.

0310a - Install Git and the DHT library Preview 05:10

Please note that the DHT22 library that I discuss in the video of this lecture is superseded by a new one.

The new library is part of Adafruit's CircuptPython project.

I recommend that you use the new library instead of the one I show in the video.

If you have already installed the old library and it works (like it does in my three instances of the RPi Full Stack that I am running), then you don't need to replace it with the new. The old library still works!

However, if you are working on a new instance of the Full Stack application, the old DHT22 library is unlikely to work for you due to dependency issues.

I will be replacing this video with a new one. In the mean time, please download the PDF document that contains a chapter of the Raspberry Pi Full Stack ebook with instructions on how to install and use the new DHT22 library.

0310b - Use the DHT22 sensor Preview 05:13

Please note that the DHT22 library that I discuss in the video of this lecture is superseded by a new one.

The new library is part of Adafruit's CircuptPython project.

I recommend that you use the new library instead of the one I show in the video.

If you have already installed the old library and it works (like it does in my three instances of the RPi Full Stack that I am running), then you don't need to replace it with the new. The old library still works!

However, if you are working on a new instance of the Full Stack application, the old DHT22 library is unlikely to work for you due to dependency issues.

I will be replacing this video with a new one. In the mean time, please download the PDF document that contains a chapter of the Raspberry Pi Full Stack ebook with instructions on how to install and use the new DHT22 library.

0340 - The Web Application Stack Preview 09:08

0350 - The Python Virtual Environment Preview 06:21

0360a - Set up system Python - preparation Preview 03:56

The setup process is available on Github: https://github.com/futureshocked/RaspberryPiFullStack_Raspbian/edit/master/CommandLineInstructions/360_seting_up_system_Python_notes.txt


For convenience, I copy it here:


ssh [email protected]

$ sudo apt-get update

$ sudo apt-get upgrade

$ sudo apt-get install build-essential

$ sudo apt-get install libncurses5-dev libncursesw5-dev libreadline6-dev libffi-dev

$ sudo apt-get install libbz2-dev libexpat1-dev liblzma-dev zlib1g-dev libsqlite3-dev libgdbm-dev tk8.5-dev libssl-dev openssl

$ sudo apt-get install python-dev


0360b - Download, compile and install Python 3 Preview 10:21

Update, February 5, 2020. At this time, Python 3.8.1 is the latest version.

To install Python 3.8.1, follow this process (you can remain as user “pi” until the last few steps that require root):


~ $ cd ~

~ $ mkdir python-source

~ $ cd python-source/

~/python-source $ wget https://www.python.org/ftp/python/3.8.1/Python-3.8.1.tgz

~/python-source $ tar zxvf Python-3.8.1.tgz

~/python-source $ cd Python-3.8.1/

~/python-source/Python-3.8.1 $ ./configure --prefix=/usr/local/opt/python-3.8.1

~/python-source/Python-3.8.1 $ make

~/python-source/Python-3.8.1 $ sudo make install


At this point, Python 3.8.1 is now installed in /usr/local/opt/python-3.8.1

Test your new Python:


~/python-source/Python-3.8.1 $ /usr/local/opt/python-3.8.1/bin/python3.8 --version


The response should be: “Python 3.8.1”

0365 - Setup the app Python Virtual Environment Preview 08:17

0430a - Setup Nginx Preview 02:22

0430b - Setup Flask Preview 03:04

0435 - A tour of a simple Flask app Preview 12:23

0440a - uWSGI installation Preview 01:52

0440b - Nginx configuration Preview 05:23

0440c - USWGI configuration Preview 04:15

0440d - USWGI and Nginx configuration testing Preview 02:28

0450 - Configure systemd to auto-start uwsgi Preview 07:59

0460a - Install SQlite3 Preview 01:46

0460b - Working with SQlite3 Preview 06:05

0470a - Static assets and the Skeleton boilerplate CSS Preview 02:15

0470b - Setup the static assets directory Preview 03:40

0470c - Introducing the Skeleton boilerplate CSS Preview 02:52

0470d - Copying files using SFTP Preview 06:56

0480 - Flask templates Preview 07:26

0497 - Debugging a Flask app Preview 07:58

0500a - Introduction to the section - Getting started with our web application Preview 01:26

0500b - Install the DHT library and the rpi-gpio module Preview 02:35

0500c - Install the DHT library and the rpi-gpio module Preview 10:22

0510 - Create a database to store sensor data Preview 07:56

0520 - Sensor data capture script Preview 06:49

0530 - Schedule sensor readings with cron Preview 09:04

0540a - Display database records in the browser - Python script Preview 05:36

0540b - Display database records in the browser - Template Preview 06:39

0560a - Introduction - Implement the datetime range selection feature Preview 03:09

0560b - Select range of records in SQLite Preview 06:16

0570 - Set datetime range in URL and show records in browser Preview 14:42

0580 - URL querystring validation Preview 06:48

0590 - Quick tidying up Preview 10:19

0595 - Adding radio buttons for quick timedate range selection Preview 09:33

0597 - Provision the Python script to work with the radio buttons Preview 10:38

0610a - Introduction to Google Charts Preview 05:05

0610b - Implementation of Google Charts Preview 10:57

0610c - Testing Google Charts Preview 02:15

0650a - Introduction to the datetime picker widget Preview 05:32

0650b - Implement the datetime picker widget Preview 06:19

0650c - Upload and test the datetime picker widget Preview 02:55

0665 - Adjust datetimes to local time zone on the client side Preview 12:30

0670a - Introduction to Arrow Preview 05:00

0670b - Implement Arrow Preview 06:06

The source code you see in this lecture has been updated with small improvements and bug fixes since the video was recorded.

You can find the latest source code on Github: https://github.com/futureshocked/RaspberryPiFullStack_Raspbian/blob/master/lab_app_v9.py

0670c - Upload timezone changes and test Preview 05:30

0680 - Link the two pages of the application Preview 07:21

Please read before you begin this section Preview 00:15

Important information relating to Plotly.

0710a - Install Plotly Preview 06:36

Plotly’s version 4 and later is “offline only”, and does not work in the way that we intend to use it in this app. Therefore, please ensure that you force the installation of Plotly version 3.10, like this:


$ pip install plotly==3.10


To learn more about Plotly 4, please review the Plotly documentation: https://plot.ly/python/getting-started/

0710b - Try out Plotly on the command line Preview 03:09

0720a - Implement Plotly support on the client side Preview 09:44

0720b - How to debug Javascript Preview 05:10

0730a - Add Plotly support to the app script Preview 09:30

0730b - Server side debugging example Preview 07:59

0810 - Setting a static IP address Preview 08:12

0850 - Expose your app to the Internet with port forwarding Preview 09:32