1
Printer Automation Script
Create a dedicated automation script to handle printer initialization and raw socket server binding.
sudo nano /usr/local/bin/wake-printer.sh
Paste the following content into the file:
#!/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
# Clean up existing processes
killall p910nd 2>/dev/null
# Force USB driver load
modprobe usblp
sleep 3
# Push firmware
cp /lib/firmware/hp/sihp1020.dl /dev/usb/lp0
sleep 3
# Launch printer daemon
nohup p910nd -b -f /dev/usb/lp0 0 >/dev/null 2>&1 &
Save (Ctrl+X, Y, Enter) and make it executable:
sudo chmod +x /usr/local/bin/wake-printer.sh
2
Configure Boot Automation
Schedule the script to run automatically 30 seconds after the Raspberry Pi finishes booting.
Scroll to the bottom and add this line:
@reboot sleep 30 && /usr/local/bin/wake-printer.sh &
Save and exit. This ensures the printer wakes up automatically even after a power cycle.
3
Disable Network Power Saving
Prevent the operating system from throttling the Wi-Fi/Ethernet controller to save power.
sudo nano /etc/NetworkManager/conf.d/default-wifi-powersave-on.conf
Ensure the file contents look like this:
[connection]
wifi.powersave = 2
Save and exit. Then update the kernel settings:
sudo nano /boot/firmware/cmdline.txt
Add usbcore.autosuspend=-1 to the end of the existing line.
4
Network Heartbeat
Set up a periodic ping to ensure the router maintains an active connection to your Pi.
Add this line to the bottom (replace 192.168.1.1 with your router's IP address):
* * * * * /usr/bin/ping -c 1 192.168.1.1 > /dev/null 2>&1
This "heartbeat" prevents the router from dropping the Pi from its active device table during periods of inactivity.
1
System Preparation & Installation
These steps install the necessary OS dependencies and compile the core OctoPrint software inside an isolated Python virtual environment.
First, update system libraries and dependencies:
sudo apt update
sudo apt install python3-pip python3-dev python3-setuptools python3-venv git libyaml-dev build-essential -y
Navigate to your home directory, create a dedicated folder, and initialize the virtual environment:
cd ~
mkdir OctoPrint
cd OctoPrint
python3 -m venv venv
Activate the environment, upgrade pip, and install OctoPrint. On newer versions of Python (like 3.13+), compiling dependencies from source can take 15-30 minutes. Be patient!
source venv/bin/activate
pip install pip --upgrade
pip install octoprint
Before proceeding, verify the installation by running the serve test:
If you see the message "Listening on http://0.0.0.0:5000", the installation was successful. Press Ctrl + C to stop the server.
2
Installing Marlin Binary Protocol
If you plan to use advanced plugins like the Firmware Updater, you may encounter a "Python marlin-binary-protocol package is NOT installed" error inside the OctoPrint web interface.
Standard installation method (ensure virtual environment is active):
pip install marlin-binary-protocol
Heatshrink Compiler Error? If the standard installation fails with heatshrink or subprocess compilation errors on newer Python environments, bypass the broken registry and install a community-patched version directly from GitHub:
pip install https://github.com/The-EG/marlin-binary-protocol/archive/refs/heads/master.zip
3
Configuring Systemd for Auto-Start
Configure a systemd service file with self-healing parameters to run OctoPrint in the background and survive sudden reboots.
Create the service configuration file:
sudo nano /etc/systemd/system/octoprint.service
Paste the following service definition (replace User=pi and paths if your username is different):
[Unit]
Description=The snappy web interface for your 3D printer
After=network-online.target
Wants=network-online.target
[Service]
Restart=always
RestartSec=5
Environment="LC_ALL=C.UTF-8"
Environment="LANG=C.UTF-8"
Type=exec
User=pi
ExecStart=/home/pi/OctoPrint/venv/bin/octoprint serve
[Install]
WantedBy=multi-user.target
Save and exit nano, then enable and start the background service:
sudo systemctl daemon-reload
sudo systemctl enable octoprint.service
sudo systemctl start octoprint.service
4
Preventing Boot-Time Timing Crashes
Raspberry Pis boot so quickly that systemd may try to start OctoPrint before the network interfaces or USB serial ports are fully initialized, causing it to crash.
Open the Raspberry Pi configuration tool:
Navigate to System Options -> Network at Boot -> Select Yes (Wait for network connection on boot). Exit the tool and reboot the Pi.
1
Retrieve Portainer Stack Configuration
A ready-to-use Docker Compose stack file has been saved in your project root. You can download or view it directly:
Z:\HomeWeb\portainer-stack.yml
Or read the generated PDF guide: Z:\HomeWeb\portainer-stack-setup.pdf
2
Portainer Stack YAML
Deploy this stack configuration in your Portainer Web Editor. Ensure the casing of the volumes path matches your NAS exactly.
version: '3.8'
services:
homeweb:
image: python:3.12-alpine
container_name: homeweb-server
network_mode: host
working_dir: /app
volumes:
- /Volume1/public/HomeWeb:/app
command: sh -c "pip install --no-cache-dir -r requirements.txt && python server.py"
restart: unless-stopped
environment:
- FLASK_ENV=production
- PYTHONUNBUFFERED=1
3
Important Notes
• Path Casing: The volume path /Volume1/public/HomeWeb is strictly case-sensitive on TerraMaster NAS. An incorrect case causes Docker to mount an empty directory.
• Network Mode: network_mode: host is required so the Python container has access to the internet to run pip install for dependencies on startup, and to bind port 3000 directly to the NAS.
• Adding Dependencies: Simply add packages to requirements.txt (like paramiko) and restart the container in Portainer to automatically install them.