pip3 install -r requirements.txt
source venv/bin/activate nohup python3 main.py &
This project sets up a simple web server on a Raspberry Pi to allow submitting tasks for printing on a thermal receipt printer.
lsusb
-
Dependencies: Ensure you have Python 3 and
pipinstalled. The required Python packages are listed inrequirements.txt.source venv/bin/activate pip3 install -r requirements.txt -
Hardware: Make sure your ESC/POS printer is connected and configured correctly for
escpos.printer.Usbto function.
To start the web server, navigate to the project directory and run:
nohup python3 bot.py
nohup python3 app.py &This command will start the Flask application in the background. The nohup command prevents the process from being terminated when you log out of your SSH session, and & runs the command in the background.
The server will be accessible on your LAN at http://192.168.x.x:8333 (replace 192.168.x.x with your Raspberry Pi's actual IP address).
You can send tasks to the printer using Apple Shortcuts by making a POST request to the /apple-shortcut-task endpoint.
Endpoint: http://192.168.x.x:8333/apple-shortcut-task (replace 192.168.x.x with your Raspberry Pi's actual IP address)
Method: POST
Content-Type: application/json
Example Request Body:
{
"task": "Remember to buy milk and eggs."
}For a more robust and manageable persistent service, especially for production environments, it is recommended to set up a systemd service. Here's a basic outline:
-
Create a service file (e.g.,
/etc/systemd/system/printer_task.service):[Unit] Description=Printer Task Server After=network.target [Service] User=pi # Replace with your Raspberry Pi username WorkingDirectory=/home/pi/printer # Replace with your project directory ExecStart=/usr/bin/python3 /home/pi/printer/app.py Restart=always [Install] WantedBy=multi-user.target
- Adjust
UserandWorkingDirectoryto match your setup. - Ensure the
ExecStartpath topython3andapp.pyis correct.
- Adjust
-
Reload systemd and enable the service:
sudo systemctl daemon-reload sudo systemctl enable printer_task.service sudo systemctl start printer_task.service -
Check status (optional):
sudo systemctl status printer_task.service ps aux | grep kill
problems to solve: dynamic pdf-html size