- Write SD Card Images Using Etcher
- Raspberry PI Stretch lite (Mirror)
- 2018-11-13-raspbian-stretch-lite.zip
- Raspberry PI Stretch lite (Mirror)
- Setup WiFi on a Pi Manually using wpa_supplicant.conf
- Enable SSH (Secure Shell) on the Raspberry Pi - METHOD 4
- Putty Download
- Raspberrypi - SSH using Windows
Insert the SD card into the Pi and power it up. Either use a keyboard and attached monitor or connect from another machine via SSH. Update the list of packages using :
sudo apt-get update
sudo apt-get upgrade
Install NGINX, pip3 and uWSGI using the following commands :
sudo apt-get install nginx
sudo apt-get install python3-dev
sudo apt-get install python3-pip
sudo python3 -m pip install --upgrade pip setuptools wheel
sudo pip3 install flask uwsgi
sudo pip3 install Adafruit_DHT
Ensure you are in the /home/pi directory using :
cd ~
Create an example Flask app by first creating a folder called "flaskapp" :
mkdir flaskapp
and setting its group owner to "www-data" :
sudo chown www-data /home/pi/flaskapp
Navigate into the directory :
cd flaskapp
Then directly download my example Flask App to the Pi using :
sudo wget https://gist.github.com/hashg/f7885e8b27578a41cd3f18e99f2fa771/archive/21003617c63e854a2e148e077fa033ff63439616.zip
Extract the contents :
sudo unzip 21003617c63e854a2e148e077fa033ff63439616.zip
Goto extracted folder and copy all the files to sudo cp * ~/flaskapp
Find out the IP address of your Pi by using :
ifconfig
I will use the example “192.168.1.99” but you should use what IP address your Pi shows under ifconfig (either against eth0 for wired connections or wlan0 for wireless connections).
sudo python3 sensor.py
ctrl + c
uwsgi --socket 0.0.0.0:8000 --protocol=http -w sensor:app
Test uWSGI Initialisation File
uwsgi --ini uwsgi.ini
ls /tmp
You should see “flaskapp.sock” listed as a file. This file only exists while uWSGI is running.
ctrl + c
Delete the default site :
sudo rm /etc/nginx/sites-enabled/default
Now copy a configuration file called "flask_proxy" :
sudo cp flask_proxy /etc/nginx/sites-available/
Finally create a link from this file to the "sites-enabled" directory using :
sudo ln -s /etc/nginx/sites-available/flask_proxy /etc/nginx/sites-enabled
sudo systemctl restart nginx
sudo cp uwsgi.service /etc/systemd/system
Restart the daemon so it picks up this new unit :
sudo systemctl daemon-reload
Now start the service :
sudo systemctl start uwsgi.service
Finally check on the status the service :
sudo systemctl status uwsgi.service
To make it run on every reboot use the command :
sudo systemctl enable uwsgi.service