Skip to content

svralph/sb-printer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

sb-printer

A Raspberry Pi print server for the Epson TM-m50II-H receipt printer. Receives print jobs over HTTP via ngrok and prints formatted receipts using a custom font and banner image.

Hardware

  • Raspberry Pi 4 Model B
  • Epson TM-m50II-H receipt printer (USB)
  • MicroSD card (32GB+)
  • USB-C power supply (15W/3A)

Files

File Description
server.py Flask server that receives print jobs and sends them to the printer
receipt.py Receipt builder — handles image rendering, font, banner tiling, and ESC/POS output
start.sh Startup script that runs Flask and ngrok together
SweetBastard-Regular.otf Custom font used for receipt text
SBDiamond.png Banner image tiled across the top and bottom of each receipt

First-time setup on a new Raspberry Pi

1. Flash the SD card

Download Raspberry Pi Imager on your laptop.

  • Device: Raspberry Pi 4
  • OS: Raspberry Pi OS Lite (64-bit)
  • Click the pencil/settings icon before writing and configure:
    • Hostname
    • Username and password
    • WiFi network name and password
    • Enable SSH (under the Services tab) → Use password authentication

Write to the SD card, insert into the Pi, and power on. Wait 90 seconds for first boot.

2. SSH into the Pi

From your laptop terminal:

ssh -v yourusername@yourhostname.local

Or use the IP address if the hostname doesn't resolve:

ssh yourusername@192.168.x.x

Find the IP by checking your router's connected devices list or running ping yourhostname.local.

3. Update the Pi

sudo apt update && sudo apt upgrade -y

4. Install dependencies

sudo apt install python3-pip python3-pil libusb-1.0-0 git -y
pip3 install flask python-escpos pyusb pillow --break-system-packages

5. Clone this repo

cd ~
git clone https://github.com/svralph/sb-printer.git
cd sb-printer
cp * ~/
cd ~

6. Prevent the kernel from claiming the USB printer

echo "blacklist usblp" | sudo tee /etc/modprobe.d/blacklist-usblp.conf
echo "install usblp /bin/false" | sudo tee -a /etc/modprobe.d/blacklist-usblp.conf
sudo update-initramfs -u

7. Install ngrok

Sign up for a free account at ngrok.com, then:

curl -s https://ngrok-agent.s3.amazonaws.com/ngrok.asc | sudo tee /etc/apt/trusted.gpg.d/ngrok.asc >/dev/null
echo "deb https://ngrok-agent.s3.amazonaws.com buster main" | sudo tee /etc/apt/sources.list.d/ngrok.list
sudo apt update && sudo apt install ngrok -y
ngrok config add-authtoken YOUR_TOKEN_HERE

8. Verify printer USB IDs

Plug in the printer and run:

lsusb

You should see the Epson listed as ID 04b8:0e34. If your printer has different IDs, update the Usb(0x04b8, 0x0e34 ...) lines in receipt.py and server.py to match.


Daily startup

Every time you need the print server running:

./start.sh

This will:

  1. Remove the usblp kernel module
  2. Start the Flask server on port 5000
  3. Start ngrok and expose it publicly

Copy the ngrok URL that appears (e.g. https://abc123.ngrok-free.app) and update it in your client app.

To run Flask and ngrok in separate terminals instead:

Terminal 1:

sudo rmmod usblp 2>/dev/null
python3 server.py

Terminal 2:

ngrok http 5000

Sending a print job

Send a POST request to your ngrok URL:

curl -X POST https://YOUR-NGROK-URL/print \
  -H "Content-Type: application/json" \
  -d '{"text": "your receipt text here"}'

Or from Python/Node:

import requests
requests.post(
    "https://YOUR-NGROK-URL/print",
    json={"text": "your receipt text here"}
)
await fetch("https://YOUR-NGROK-URL/print", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({ text: "your receipt text here" })
});

Changing WiFi networks

If the Pi is already running and you want to add a new network:

sudo nmcli dev wifi connect "NetworkName" password "NetworkPassword"

If you can't SSH in (e.g. moving to a new location), reflash the SD card with the new WiFi credentials using Raspberry Pi Imager, then clone this repo again after booting.


Troubleshooting

SSH times out — SSH may not be enabled. Reflash the SD card and make sure "Enable SSH" is checked in the Imager settings.

Printer not found (lsusb shows nothing) — Check USB cable, try a different port, make sure the printer is powered on.

[Errno 16] Resource busy — The usblp kernel module has reloaded. Run sudo rmmod usblp then restart Flask.

ngrok URL not working — The URL changes every time ngrok restarts. Check the current URL in the ngrok terminal and update your client app.

Nothing prints but no error — Check the printer display for error messages, make sure paper is loaded, and try the printer's feed button to confirm it's online.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors