PeopleSpace Raspberry Pi Setup Notes
Currently, there are 13 Raspberry Pi’s:
octo-1, octo-2, …, and octo-9 are running OctoPrint
They are connected to the Wi-Fi Router via ethernet cable to ensure stable connectivity.
Their LAN DHCP-reserved IP addresses are assigned to match the device number for easy identification (i.e., octo-1 gets 192.168.193.1, octo-2 gets 192.168.193.2, and so on).
Their Zerotier IP addresses also follow the same pattern (i.e. octo-1 gets 192.168.195.1, octo-2 gets 192.168.195.2, and so on.)
Each device communicates with the NAS via the LAN instead of the Zerotier network to avoid encryption overhead.
ps-nas is running as network attached storage
Runs SAMBA server to provide network access to its shared folder.
zerotier-pi is running as a layer-3 router to make devices on the 192.168.193.254/24 accessible to clients connected to the Zerotier network "peoplespace" (ID: a84ac5c10a70ccf7).
timelapse-0 and timelapse-1 are running as time lapse cameras
They are configured to connect to "lph-wifi" by default and with "ps-vip" as fallback. When a device connects to "ps-vip" (instead of "lph-wifi") as fallback, you will only be able to connect to the device via its Zerotier IP address.
Setting up and Raspberry Pi to run OctoPrint
There are two options to set up OctoPrint on a Raspberry Pi— via OctoPi or via manually configuration. OctoPi is a SD card image of the Raspberry Pi OS that includes the OctoPrint software. It is the recommended way to set up OctoPrint on a Raspberry Pi. This document also provides instructions on how to set up a Raspberry Pi OS installation with OctoPrint. Aside from setting up OctoPrint on Raspberry Pi OS, we need a few other additional customizations to fit our physical environment.
OctoPi Setup
This section provides instructions on how to configure a Raspberry Pi to run OctoPrint via the OctoPi image.
Download and install Etcher (from Balena) — it is a piece of software that helps you properly write pre-built images onto SD cards. It's recommended by OctoPi author(s).
https://etcher.io/Download latest version of OctoPi from OctoPrint's website:
https://octoprint.org/download/Use Etcher to write the downloaded OctoPi image onto an SD card. When done, Etcher auto-unmounts the SD card.
Eject and re-insert the SD card to re-mount the SD card.
Modify the content of the SD card with custom settings.
Setup WiFi by editing octopi-wpa-supplicant.txt.
Update the network entry with the desired WiFi's SSID and PSK (i.e., Pre-Shared Key— or password). PSK can be in plaintext form or in raw-key form (raw-key form conceals the original plaintext password). You can make raw keys with https://www.wireshark.org/tools/wpa-psk.html. For example, for a WiFi AP (SSID: "waffle-house", PSK: "hunter2"), you define the network entry like below:
Plaintext form (Note: PSK is in quotes.):
network={
ssid="waffle-house"
psk="hunter2"
}Raw-key form (Note: PSK is not in quotes.):
network={
ssid="waffle-house"
psk=177cef9593<...redacted...>891ac0cce9
}Change the country code from GB to US:
country=USEnable SSH by creating a file called ssh in the root folder (if it doesn't already exist). Execute the following command in SD's card's root folder
touch ./sshAssign a unique hostname by creating a file called octopi-hostname.txt. The first line of the text file will be the hostname. (e.g., "octo-1"):
echo "<device-hostname>" > ./octopi-hostname.txtAssign a unique password (e.g, "charlie-alpha-tango"):
echo "<login-password-for-pi>" > ./octopi-password.txtUnmount and eject SD card.
Insert SD card into Raspberry Pi.
Turn on the Raspberry Pi.
Verify the Pi is reachable via the network using the following commands (See: https://raspberrypi.stackexchange.com/questions/13936):
ping <device-hostname>
arp -na | grep -i b8:27:eb
sudo nmap -sP 192.168.1.0/24 | awk '/^Nmap/{ip=$NF}/B8:27:EB/{print ip}'
Login to Pi via SSH.
ssh pi@<device-hostname-or-ip>Exit the SSH session
exit
Manual Setup
Download and install Etcher (from Balena) — it is a piece of software that helps you properly write pre-built images onto SD cards. It's recommended by OctoPi author(s).
https://etcher.io/Download latest version of Raspberry Pi OS (32-bit) Lite:
https://www.raspberrypi.org/downloads/raspberry-pi-os/Use Etcher to write the downloaded OctoPi image onto an SD card. When done, Etcher auto-unmounts the SD card.
Eject and re-insert the SD card to re-mount the SD card.
Modify the content of the SD card with custom settings.
Setup Wi-Fi by creating a file called wpa_supplicant.conf.
Enter the following as its content:
country=US
update_config=1
ctrl_interface=/var/run/wpa_supplicant
network={
ssid="<your_ssid_case_sensitive>"
psk="<your_password>"
}
Replace <your_ssid_case_sensitive> with your desired Access Point's SSID.
Replace <your_password> with your desired Access Point's PSK (i.e., Pre-Shared Key— or password). It can be in plaintext form or in raw-key form (raw-key form conceals the original plaintext password). You can make raw keys with https://www.wireshark.org/tools/wpa-psk.html. For example, for a WiFi AP (SSID: "waffle-house", PSK: "hunter2"), you define the network entry like below:
Plaintext form (Note: PSK is in quotes.):
network={
ssid="waffle-house"
psk="hunter2"
}Raw-key form (Note: PSK is not in quotes.):
network={
ssid="waffle-house"
psk=177cef9593<...redacted...>891ac0cce9
}
Enable SSH by creating a file called ssh in the root folder (if it doesn't already exist). Execute the following command in SD's card's root folder
touch ./sshAssign a unique hostname by creating a file called octopi-hostname.txt. The first line of the text file will be the hostname. (e.g., "octo-1"):
echo "<device-hostname>" > ./octopi-hostname.txtAssign a unique password (e.g, "charlie-alpha-tango"):
echo "<login-password-for-pi>" > ./octopi-password.txt
Unmount and eject SD card.
Insert SD card into Raspberry Pi.
Turn on the Raspberry Pi.
Verify the Pi is reachable via the network using the following commands (See: https://raspberrypi.stackexchange.com/questions/13936):
ping <device-hostname>
arp -na | grep -i b8:27:eb
sudo nmap -sP 192.168.1.0/24 | awk '/^Nmap/{ip=$NF}/B8:27:EB/{print ip}'
Login to Pi via SSH. Enter "raspberry" when prompted for password.
ssh pi@<device-hostname-or-ip>Change default password for pi
passwdinstall OctoPrint (see https://community.octoprint.org/t/setting-up-octoprint-on-a-raspberry-pi-running-raspbian/2337)
sudo apt install python-pip \
python-dev \
python-setuptools \
python-virtualenv \
git libyaml-dev build-essential
cd ~
virtualenv oprint
source oprint/bin/activate
pip install pip --upgrade
pip install octoprint
sudo usermod -a -G tty pi
sudo usermod -a -G dialout pi
Configure OctoPrint to start automatically on boot
Add start script template
wget https://github.com/foosel/OctoPrint/raw/master/scripts/octoprint.init
sudo mv octoprint.init /etc/init.d/octoprint
wget https://github.com/foosel/OctoPrint/raw/master/scripts/octoprint.default
sudo mv octoprint.default /etc/default/octoprint
sudo chmod +x /etc/init.d/octoprint
Modify /etc/default/octoprint
Open /etc/default/octoprint for editing:
sudo vi /etc/default/octoprintChange the DAEMON variable to match the following:
DAEMON=/home/pi/oprint/bin/octoprintComment out the following line (if it exists) to avoid making the OctoPrint run at the highest priority:
# NICELEVEL=-2Save and exit
Add the scripts to autostart using the following command
sudo update-rc.d octoprint defaultsExecute the following commands to start/monitor the service
sudo systemctl start octoprint.service
sudo systemctl status octoprint.service
Install rng-tools to use hardware generated random number
sudo apt-get install rng-toolsInstall mjpg-streamer for accessing cameras attached to the raspberry pi
Download source and compile it
sudo apt-get install cmake libjpeg62-turbo-dev git
cd ~
git clone https://github.com/jacksonliam/mjpg-streamer.git
cd mjpg-streamer/mjpg-streamer-experimental
make
sudo make install
Setup daemon to start it up on boot (see: https://github.com/ntoff/mjpeg-streamer-octoprint-daemon)
cd ~
git clone https://github.com/ntoff/mjpeg-streamer-octoprint-daemon
cd ~/mjpeg-streamer-octoprint-daemon/_root_
sudo cp ./etc/default/webcamd /etc/default/webcamd
sudo cp ./etc/init.d/webcamd /etc/init.d/webcamd
sudo cp ./bin/webcamd /bin/webcamd
sudo chmod +x /etc/init.d/webcamd
sudo chmod +x /bin/webcamd
sudo update-rc.d webcamd defaults
sudo systemctl start webcamd.service
sudo systemctl status webcamd.service
Customize daemon with configuration values (see: https://github.com/jacksonliam/mjpg-streamer/blob/master/mjpg-streamer-experimental/plugins/input_raspicam/README.md)
sudo tee /boot/octopi.txt << EOL
#camera="raspi"
camera="auto"
camera_usb_options="-r 1280x720 -f 30"
camera_raspi_options="-x 1280 -y 720 -fps 30"
EOL
Install Haproxy (reverse proxy) so that we can access OctoPrint on port 80.
Install haproxy
sudo apt install haproxybackup existing configuration file
sudo cp /etc/haproxy/haproxy.cfg /etc/haproxy/haproxycreate new configuration file
sudo tee /etc/haproxy/haproxy.cfg << EOL
global
maxconn 4096
user haproxy
group haproxy
daemon
log 127.0.0.1 local0 debug
defaults
log global
mode http
option httplog
option dontlognull
retries 3
option redispatch
option http-server-close
option forwardfor
maxconn 2000
timeout connect 5s
timeout client 15min
timeout server 15min
frontend public
bind :::80 v4v6
use_backend webcam if { path_beg /webcam/ }
default_backend octoprint
backend octoprint
reqrep ^([^\ :]*)\ /(.*) \1\ /\2
option forwardfor
server octoprint1 127.0.0.1:5000
backend webcam
reqrep ^([^\ :]*)\ /webcam/(.*) \1\ /\2
server webcam1 127.0.0.1:8080
EOL
Modify OctoPrint's configuration file so that its built-in Discovery plugin reports itself as accessible on port 80 instead of port 5000 (default).
Open OctoPrint's configuration file
vi ~/.octoprint/config.yamlAdd the following line under the "discovery:" section with the proper indentations
publicPort: 80Save and exit
Install FFMPEG
sudo apt-get install ffmpegInstall lsof so we can check for list of open files in htop
sudo apt-get install lsofExit the SSH session
exit
Post-Setup Configurations
Copy SSH key to remote Pi
ssh-copy-id pi@<device-hostname-or-ip>Login to Pi via SSH
ssh pi@<device-hostname-or-ip>Configure environment settings:
Open raspi-config by executing the following command:
sudo raspi-configChange hostname from default of "raspberrypi" to something unique (e.g. octo-1)
Change timezone to local time zone (e.g., America/Los Angeles)
Change locale to en_GB.UTF-8 to en_US.UTF-8.
For interfacing options, enable camera interface (if available).
Update software listings and installed packages
sudo apt-get update
sudo apt-get upgrade
sudo apt-get dist-upgradeInstall ZeroTier:
curl -s https://install.zerotier.com | sudo bashJoin ZeroTier Network
zerotier-cli join <network-id>Install Vim
sudo apt-get install vimConfigure default text editor to use vim.basic instead of nano:
sudo update-alternatives --config editorDisable prompting of password when executing command via sudo:
Run visudo to bring up editor to edit sudoers.d files
sudo visudoAppend the following line to the end of file. Save then exit.
pi ALL=(ALL:ALL) NOPASSWD:ALLOr, do the same with the following command and uncomment the line in it:
sudo visudo -f /etc/sudoers.d/010_pi-nopasswdIncrease Raspberry Pi camera video resolution (from 640x480 to 1280x720)
Open octopi.txt for editing
sudo vi /boot/octopi.txtInclude the following line
camera_usb_options="-r 1280x720 -f 30"
Save and exit
Setup SAMBA mount to network attached storage (i.e., ps-nas) using autofs instead of fstab (autofs connects on-demand).
sudo mkdir /mnt/octolapse-timelapse
sudo apt-get install autofs
sudo tee ~/.smbcredentials < EOL
username=<samba_account_username>
password=<samba_account_password>
EOL
sudo tee /etc/auto.master.d/smb.autofs << EOL
/- /etc/auto.smb.shares --timeout 15 browse
EOL
sudo tee /etc/auto.smb.shares << EOL
/mnt/public-data/ -fstype=cifs,uid=1000,gid=1000,rw,noperm,dir_mode=0775,file_mode=0664,credentials=/home/pi/.smbcredentials,iocharset=utf8 ://192.168.193.100/public-data/
/mnt/octoprint-timelapse/ -fstype=cifs,uid=1000,gid=1000,rw,noperm,dir_mode=0775,file_mode=0664,credentials=/home/pi/.smbcredentials,iocharset=utf8 ://192.168.193.100/octoprint-timelapse/octo-<#>/
/home/pi/.octoprint/uploads/nas/ -fstype=cifs,uid=1000,gid=1000,rw,noperm,dir_mode=0775,file_mode=0664,credentials=/home/pi/.smbcredentials,iocharset=utf8 ://192.168.193.100/octoprint-data/printer-<#>/
EOL
sudo systemctl restart autofs
Configure OctoPrint
Configure initial settings
Enable login security
Provide login and password
Disable connectivity check
Disable anonymous usage reporting
Disable plugin blacklisting
Create printer profile
Update OctoPrint Settings values
Click the Wrench icon to open the Settings menu.
Make the following changes
Features >
Features > Analyze gcode for time and model size estimate >
NeverWebcam and Timelapse >
Webcam >
Check "Enable webcam support"
Stream URL
/webcam/?action=streamTimelapse Recordings >
Snapshot URL:
http://127.0.0.1:8080/?action=snapshotPath to FFMPEG
/usr/bin/ffmpegOctoPrint >
Server >
Restart OctoPrint:
sudo service octoprint restartRestart system:
sudo shutdown -r nowShutdown system:
sudo shutdown -h nowPlugin Manager > Get More >
Fullscreen Webcam
Firmware Updater
Software update >
Perform update
Save
Click the Power button > Reboot system