-
Install
Raspberry Pi OS Lite (32-bit)
with SSH enabled. With i.e. Raspi Card Imager for Android. Available in Play Store. -
Edit password with
passwd
-
Edit
/etc/wpa_supplicant/wpa_supplicant.conf
to enter WiFi network and password. Add the following to the end of the file:network={ ssid="Wifi name" psk="Wifi password" }
-
Execute
hostname -I
to check assigned IP adress -
Edit the hostname of the raspberry using
sudo raspi-config
.System options
->Hostname
-
Login to raspberry via SSH using
ssh pi@
hostname
- Install git
ssh-keygen -t ed25519 -C "[email protected]"
- Enter a passphrase
eval "$(ssh-agent -s)"
(?)ssh-add ~/.ssh/id_ed25519
(?)- Add the ssh key to GitHub. Copy and paste the contents of
~/.ssh/id_ed25519.pub
-
Guide from here.
-
sudo apt-get update sudo apt-get upgrade
-
sudo apt-get remove apache2
(in case apache is installed) -
sudo apt-get install nginx
-
Confirm by browsing to
http://
your-hostname
/
-
Create
/etc/nginx/sites-available/
url
.conf
server { listen 4000; server_name *url here, e.g. raps.hilkojj.nl*; location / { proxy_pass http://localhost:8000; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "Upgrade"; } }
NOTE: The
Upgrade
andConnection
headers are to support Websockets. -
sudo ln -s /etc/nginx/sites-available/
url
.conf /etc/nginx/sites-enabled/
url
.conf
-
Confirm with
sudo nginx -t
-
Reload NGINX
sudo systemctl reload nginx
-
Read logs with
sudo tail -f /var/log/nginx/access.log
or
sudo tail -f /var/log/nginx/error.log
- Install firewall
sudo apt install ufw
sudo ufw limit 22
limited SSH accesssudo ufw allow 80
unlimited access to default NGINX http server (required for certbot)sudo ufw allow 443
unlimited access to httpS server- Confirm with
sudo ufw show added
- Enable with
sudo ufw enable
- Check status anytime with
sudo ufw status
- Give the raspberry a static local IP adress.
- Using NAT forward port 443 from raspberry to port 443
- Using NAT forward port 80 from raspberry to port 80
- Now default NGINX server is visible on
http://
url
. This is needed for certbot
-
sudo apt install letsencrypt
-
Confirm renewal bot is running:
sudo systemctl status certbot.timer
-
apt install python3-certbot-nginx
-
sudo certbot --nginx --agree-tos --preferred-challenges http -d raps.hilkojj.nl
certbot will try to retrieve a file for confirmation from the provided url, so make sure port 80 is also port forwarded.
-
Now everything that is hosted locally on port 8000 will be accessible through HTTPS (port 443):
https://
url
-
Install Pip3 and other useful utilities:
sudo apt-get install python3-dev python3-pip sudo python3 -m pip install --upgrade pip setuptools wheel
-
Install pipenv to keep track of installed packages for this project:
pip3 install --user pipenv
-
Enter the environment with
pipenv shell
.Use
sudo -E env PATH=$PATH python boot.py
to run script with sudo -
Run boot.py on each reboot:
sudo nano /etc/crontab
. -
Add
@reboot pi cd /home/pi/hamsterraps/ && sudo -E env PATH=$PATH /home/pi/.local/bin/pipenv run sh ./boot.sh
to end of file.sudo
is needed in order forws2811_init()
to succeed. (-5
return code otherwise).sudo -E env PATH=$PATH
explained here.
sudo pip3 install Adafruit_DHT
- DHT11 sensor pins are: Signal, 5V, Ground
- Script uses GPIO pin 4, 4th pin on left column
-
copied from here
import Adafruit_DHT import time DHT_SENSOR = Adafruit_DHT.DHT11 DHT_PIN = 4 while True: humidity, temperature = Adafruit_DHT.read(DHT_SENSOR, DHT_PIN) if humidity is not None and temperature is not None: print("Temp={0:0.1f}C Humidity={1:0.1f}%".format(temperature, humidity)) else: print("Sensor failure. Check wiring."); time.sleep(3);
- Add this to the end of
/boot/config.txt
:More info on waveshare displaymax_usb_current=1 hdmi_group=2 hdmi_mode=87 hdmi_cvt 800 480 60 6 0 0 0 hdmi_drive=1
- Enable passwordless login to console with
sudo raspi-config
-> 1 -> S5 - Follow this (or this) guide on starting up Chromium without a window manager.
- Also don't forget to add this to
~/.bash_profile
, otherwise~/.bashrc
and~/.profile
won't work anymore:if [ -n "$BASH_VERSION" ]; then # include .bashrc if it exists if [ -f "$HOME/.bashrc" ]; then . "$HOME/.bashrc" fi if [ -f "$HOME/.profile" ]; then . "$HOME/.profile" fi fi
- Install an emoji font with
sudo apt-get install fonts-noto-color-emoji
- Enable camera with
sudo raspi-config
and reboot - Install ffmpeg
sudo apt install ffmpeg