This guide covers multiple deployment options for your ticket printer application.
- Raspberry Pi with Raspberry Pi OS installed
- Netum 58mm thermal printer
- USB cable to connect printer to Pi
Choose one of these methods:
Method A: Using USB Flash Drive
# On your Mac:
# 1. Copy the entire folder to a USB drive
cp -r /path/to/ticket-printer-app /Volumes/YOUR_USB_NAME/
# 2. Insert USB into Raspberry Pi
# 3. On the Pi, copy files to home directory:
cp -r /media/pi/*/ticket-printer-app ~/
cd ~/ticket-printer-appMethod B: Using SCP (Network Transfer)
# On your Mac, from the project directory:
scp -r /path/to/ticket-printer-app [email protected]:/home/pi/
# Then SSH into the Pi:
ssh [email protected]
cd ~/ticket-printer-appMethod C: Using Git
# On your Mac:
cd /path/to/ticket-printer-app
git init
git add .
git commit -m "Initial commit"
# Create a repo on GitHub and push
git remote add origin YOUR_GITHUB_URL
git push -u origin main
# On Raspberry Pi:
git clone YOUR_GITHUB_URL
cd ticket-printer# Make sure you're in the project directory
cd ~/ticket-printer-app
# Make the setup script executable
chmod +x setup.sh
# Run the setup
./setup.shThis will:
- Install Python and system dependencies
- Install printer drivers
- Install Python packages
- Set up permissions
- Create a systemd service
# Connect your printer via USB
# Find the printer's USB ID:
sudo lsusbYou should see something like:
Bus 001 Device 003: ID 0416:5011 Netum printer
If your printer has different USB IDs, edit app.py:
nano app.pyLook for lines 19-20:
USB_VENDOR = int(os.getenv('USB_VENDOR', '0x0416'), 16)
USB_PRODUCT = int(os.getenv('USB_PRODUCT', '0x5011'), 16)Replace 0x0416 and 0x5011 with your printer's IDs from lsusb.
python3 -c "
from escpos.printer import Usb
p = Usb(0x0416, 0x5011)
p.text('Test print')
p.cut()
"Option A: Run Manually (for testing)
python3 app.pyOption B: Run as a Service (starts on boot)
sudo systemctl start ticket-printer
sudo systemctl enable ticket-printer
sudo systemctl status ticket-printerhostname -IAccess from any device: http://YOUR_PI_IP:5000
Test the web interface locally:
# Install dependencies
pip3 install -r requirements.txt
# Run the app
python3 app.pyOpen browser to: http://localhost:5000
Note: Without a printer connected, the print operations will fail, but you can test the web interface.
# On Raspberry Pi, pair Bluetooth printer:
sudo bluetoothctl
scan on
# Wait to see your printer, then:
pair MAC_ADDRESS
trust MAC_ADDRESS
exit
# Bind to serial port:
sudo rfcomm bind /dev/rfcomm0 MAC_ADDRESS
# Set environment variables:
export PRINTER_TYPE=bluetooth
export SERIAL_PORT=/dev/rfcomm0
# Run the app
python3 app.py# Enable serial interface:
sudo raspi-config
# Navigate to: Interface Options > Serial Port > Enable
# Set environment variables:
export PRINTER_TYPE=serial
export SERIAL_PORT=/dev/ttyAMA0
# Run the app
python3 app.py# Set environment variables:
export PRINTER_TYPE=network
export NETWORK_HOST=192.168.1.100
# Run the app
python3 app.pyThe setup script creates a systemd service. To manage it:
# Start the service
sudo systemctl start ticket-printer
# Stop the service
sudo systemctl stop ticket-printer
# Restart the service
sudo systemctl restart ticket-printer
# Check status
sudo systemctl status ticket-printer
# View logs
sudo journalctl -u ticket-printer -f
# Enable on boot
sudo systemctl enable ticket-printer
# Disable on boot
sudo systemctl disable ticket-printerCreate a .env file or set systemd environment:
sudo systemctl edit ticket-printerAdd:
[Service]
Environment="PRINTER_TYPE=usb"
Environment="USB_VENDOR=0x0416"
Environment="USB_PRODUCT=0x5011"Then:
sudo systemctl daemon-reload
sudo systemctl restart ticket-printer# Add user to printer groups
sudo usermod -a -G lp,dialout pi
# Fix USB permissions temporarily
sudo chmod 666 /dev/bus/usb/*/*
# Log out and back in for group changes to take effect-
Check USB connection:
sudo lsusb
-
Check permissions:
ls -l /dev/ttyUSB0 # or relevant device sudo chmod 666 /dev/ttyUSB0 -
Try different USB ports
-
Verify USB vendor/product IDs match configuration
# Check service status
sudo systemctl status ticket-printer
# View detailed logs
sudo journalctl -u ticket-printer -n 50
# Try running manually to see errors
cd ~/ticket-printer-app
python3 app.py-
Check if app is running:
ps aux | grep app.py -
Check if port 5000 is in use:
sudo netstat -tulpn | grep 5000 -
Check firewall:
sudo ufw allow 5000/tcp
-
Verify IP address:
hostname -I
# Check if device is paired
bluetoothctl devices
# Check rfcomm binding
rfcomm
# Rebind if needed
sudo rfcomm bind /dev/rfcomm0 MAC_ADDRESSTest if the service is working:
# From the Raspberry Pi or network:
curl http://localhost:5000/healthShould return:
{
"status": "healthy",
"printer_connected": true
}# Stop the service
sudo systemctl stop ticket-printer
# Pull latest changes (if using git)
git pull
# Or update files manually
# Copy new files to ~/ticket-printer-app/
# Install new dependencies (if any)
pip3 install -r requirements.txt
# Restart service
sudo systemctl start ticket-printer- Change default Flask debug mode for production
- Consider adding authentication if exposed to internet
- Use HTTPS for production deployments
- Set up firewall rules appropriately
- Files transferred to Raspberry Pi
- Dependencies installed
- Printer connected and detected
- Configuration updated with correct printer IDs
- Test print successful
- Application running (manually or as service)
- Web interface accessible from network
- Can submit and print tickets successfully
Check the main README.md for more detailed information and troubleshooting tips.