Skip to content

Commit b2d2a9b

Browse files
authored
Merge pull request #13 from bitrate16/refactor-to-peripage
Refactor to peripage
2 parents c9cf0ac + 8433911 commit b2d2a9b

18 files changed

Lines changed: 2111 additions & 1433 deletions

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*__pycache__*

README.md

Lines changed: 90 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,41 @@
1-
# ppa6-python
2-
### Python module for printing on Peripage A6 and A6+
1+
# peripage-python
2+
### Python module for printing on Peripage printers
33

44
**This project is a continued development of the [original project](https://github.com/eliasweingaertner/peripage-A6-bluetooth) made by [Elias Weingärtner](https://github.com/eliasweingaertner). This module combined all results of reverse engineering of the Peripage A6/A6+ protocol in a python utility providing interface and CLI tool for printing on this thermal printer.**
55

66
## [The original introduction](https://github.com/eliasweingaertner/peripage-A6-bluetooth#introduction)
77

8-
The Peripage A6 F622 is an inexpensive portable thermal printer. It provides both Bluetooth and USB connectivity. Unlike most other thermo printers it **does not** seem to support ESC/POS or any other standardized printer control language.
8+
The Peripage A6 F622 is an inexpensive portable thermal printer. It provides both Bluetooth and USB connectivity. Unlike most other thermo printers it **does not** seem to support ESC/POS or any other standardized printer control language.
99

1010
So far, the Peripage A6 F622 can be only controlled using a proprietary app (iOS / Anndroid). There is also a driver for Windows with many limitations, most notably the need of defining a page size before printing; this is a huge limitation, as the Peripage prints on continuous form paper.
1111

12-
The script provided here was built based on an analysis of captured Bluetooth traffic between the printer and an Android device. The Peripage A6 uses the serial profile (BTSPP) and RFCOMM.
12+
The script provided here was built based on an analysis of captured Bluetooth traffic between the printer and an Android device. The Peripage A6 uses the serial profile (BTSPP) and RFCOMM.
1313

1414
Essentially, the script takes an input images, scales it to the printers native X resolution of 384 pixels, and then sends it to the printer.
1515

16-
## Current abilities
16+
## Deprecation Warning
17+
18+
**The latest version ot `ppa6-python` module is deprecated due the major update with new models support and better module naming**
19+
20+
## Features
1721

1822
* Printing text of any length encoded in ASCII
1923
* Printing Images using PIL library
20-
* Printing raw bytes representing image in binary (black/white) form
21-
* Printing a page break of desired size (in pixels)
22-
* Printing using generator/iterator which returns image row by row in form of bytes or PIL Images
24+
* Printing Images row-by row using binary row representation
25+
* Printing page breaks using paper feed
26+
* Printing using generator/iterator that return bytes for each row, chunks of bytes for each row, images
2327
* Requesting printer details (Serial Number, Name, Battery Level, Hardware Info and an option the meaning of which i don't know)
24-
* Configuring print concentration (light, gray, black)
28+
* Configuring print concentration (temperature)
29+
* Changing printer serial number
2530
* Configuring printer poweroff timeout
31+
* Supported printers:
32+
* Peripage A6
33+
* Peripage A6+
34+
* Peripage A40
35+
36+
## Prerequisites
2637

27-
## Prerequirements
28-
* Peripage A6/A6+ printer
38+
* Peripage A6/A6+/A40/e.t.c printer
2939
* Python 3
3040

3141
## Installation
@@ -40,35 +50,18 @@ pip install . --user
4050
**Install from pypi using pip**
4151

4252
```
43-
pip install ppa6
53+
pip install peripage
4454
```
4555

4656
## Dependencies
47-
* `PyBluez==0.30`
48-
* `Pillow==8.1.2`
49-
* `argparse==1.1` (for CLI)
57+
58+
* `PyBluez>=0.30`
59+
* `Pillow>=8.1.2`
60+
* `argparse>=1.1`
5061

5162
Install dependencies with
5263
`pip install -r requirements.txt`
5364

54-
On windows you may need to install PyBluez 0.3
55-
```
56-
git clone https://github.com/pybluez/pybluez
57-
cd pybluez
58-
pip install . --user
59-
```
60-
61-
On raspberry pi it may require to install additional libraries
62-
```
63-
sudo apt install libbluetooth-dev libopenjp2-7 libtiff5
64-
```
65-
66-
And in some cases you will have to restart the bluetooth adapter and service on raspberry pi when it fails to connect or device is busy
67-
```
68-
sudo systemctl restart bluetooth
69-
sudo hciconfig hci0 reset
70-
```
71-
7265
## Identify printer Bluetooth MAC address
7366

7467
**On linux:**
@@ -100,68 +93,84 @@ Scanning bluetooth devices... please wait.
10093
00:15:83:15:bc:5f Imaging PeriPage+BC5F
10194
```
10295

96+
## Troubleshooting
97+
98+
> Windows installation requires installing PyBluez from master branch as pypi module is not updated
99+
100+
```
101+
pip install git+https://github.com/pybluez/pybluez@master#egg=pybluez --user
102+
```
103+
104+
> Raspberry PI installation requires additional libraries
105+
106+
```
107+
sudo apt install libbluetooth-dev libopenjp2-7 libtiff5
108+
```
109+
110+
> Some cases may require restarting bluetooth adapter
111+
112+
```
113+
sudo systemctl restart bluetooth
114+
sudo hciconfig hci0 reset
115+
```
116+
103117
## CLI usage
104118

105119
**On linux**
106120

107121
Install module and run
108-
`ppa6 <args>`
122+
`peripage <args>`
109123

110124
**On windows**
111125

112126
Install module and run
113-
`python -m ppa6 <args>`
127+
`python -m peripage <args>`
114128

115129
### Options
116130

117131
```
118-
usage: ppa6 [-h] -m MAC [-c [0-2]] [-b [0-255]] [-p {A6,A6p,A6+}] [-n]
119-
(-t TEXT | -s | -i IMAGE | -q QR | -e)
132+
$ python -m peripage -h
133+
usage: __main__.py [-h] -m MAC [-c [0-2]] [-b [0-255]] -p {A6,A6p,A40} (-t TEXT | -s | -i IMAGE | -q QR | -e)
120134
121-
Print on a Peripage A6 / A6+ via bluetooth
135+
Print on a Peripage printer via bluetooth
122136
123137
optional arguments:
124138
-h, --help show this help message and exit
125139
-m MAC, --mac MAC Bluetooth MAC address of the printer
126140
-c [0-2], --concentration [0-2]
127-
Concentration value for printing (0, 1, 2)
141+
Concentration value for printing (temperature)
128142
-b [0-255], --break [0-255]
129-
Size of the break that should be inserted after the
130-
print (max 255)
131-
-p {A6,A6p,A6+}, --printer {A6,A6p,A6+}
132-
Printer model name (A6 or A6+/A6p (both allowed))
133-
-n, --newline Force printer to add newline at the end of the printed
134-
text and flush the buffer
135-
-t TEXT, --text TEXT ASCII text that should be printed. Add a line break at
136-
the end of the string to avoid it being cut. String
137-
can be empty, so just page break will be printed
138-
-s, --stream Reads an input from stdin and prints as ASCII text
143+
Size of the break inserted after printed image or text
144+
-p {A6,A6p,A40}, --printer {A6,A6p,A40}
145+
Printer model selection
146+
-t TEXT, --text TEXT ASCII text to print. Text must be ASCII-safe and will be filtered for invalid characters
147+
-s, --stream Print text received from STDIN, line by line. Text must be ASCII-safe and will be filtered for invalid characters
139148
-i IMAGE, --image IMAGE
140-
Path to the image that should be printed
141-
-q QR, --qr QR String for QR code print
142-
-e, --introduce Ask the printer to introduce himself
149+
Path to the image for printing
150+
-q QR, --qr QR String to convert into a QR code for printing
151+
-e, --introduce Ask the printer to introduce itself
143152
```
144153

145154
### Print image example
146155

147-
**Print image from [file](https://github.com/bitrate16/ppa6-python/blob/main/honk.png) with following break for 100px and concentration set to 2 (HIGH) on A6+**
156+
**Print image from [file](https://github.com/bitrate16/peripage-python/blob/main/honk.png) with following break for 100px and concentration set to 2 (HIGH) on A6+**
148157
```
149-
ppa6 -m 00:15:83:15:bc:5f -p A6p -b 100 -c 2 -i honk.png
158+
peripage -m 00:15:83:15:bc:5f -p A6p -b 100 -c 2 -i honk.png
150159
```
151160

152161
### Print text example
153162

154163
**Print some random text followed by newline and break for 100px on A6+**
155164
```
156-
ppa6 -m 00:15:83:15:bc:5f -p A6p -b 100 -t "HONK" -n
165+
peripage -m 00:15:83:15:bc:5f -p A6p -b 100 -t "HONK" -n
157166
```
158167
Newline is required to fush the internal printer buffer and force it to print all text without cutting
159168

160-
### Print Service example
169+
## Print Service
161170

162171
**Print 50 text tasks on A6+**
163172
```python
164-
import ppa6
173+
import peripage
165174
import print_service
166175

167176
# Ping battery every 60 seconds
@@ -170,13 +179,14 @@ import print_service
170179
# Wait 1 second before send after connecting/reconnecting to printer
171180
# Print only after pinging printer and waiting for 1 second
172181
service = print_service.PrintService(60, 5, 5, 1, 1)
173-
service.start('00:15:83:15:bc:5f', ppa6.PrinterType.A6p)
182+
service.start('00:15:83:15:bc:5f', peripage.PrinterType.A6p)
174183
for i in range(50):
175184
service.add_print_ascii(f'number {i}', flush=True)
176185
```
177186
Newline is required to fush the internal printer buffer and force it to print all text without cutting
178187

179-
### Suggestions
188+
## Recommendations
189+
180190
* Don't forget about concentration, this can make print brighter and better visible.
181191
* Split long images into multiple print requests with cooldown time for printer (printer may overheat during a long print and will stop printing for a while. This will result in partial print loss because the internal buffer is about 250px height). For example, when you print [looooooooooooooooooooooooooooooongcat.jpg](http://lurkmore.so/images/9/91/Loooooooooooooooooooooooooooooooooooooooooongcat.JPG), split it into at least 20 pieces with 1-2 minutes delay because you will definetly loose something without cooling. Printer gets hot very fast. Yes, it was the first that i've printed.
182192
* Be carefull when printing lots of black or using max concentration, as i said, printer heats up very fast.
@@ -186,7 +196,9 @@ Newline is required to fush the internal printer buffer and force it to print al
186196

187197
## Code example
188198

189-
View this [python notebook](https://github.com/bitrate16/ppa6-python/blob/main/notebooks/ppa6-tutorial.ipynb) for tutorial
199+
View this [python notebook](https://github.com/bitrate16/peripage-python/blob/main/notebooks/peripage-tutorial.ipynb) for tutorial
200+
201+
View this [python notebook](https://github.com/bitrate16/peripage-python/blob/main/notebooks/Test-notebook.ipynb) for test
190202

191203
## Printer disassembly
192204

@@ -196,20 +208,33 @@ View this [python notebook](https://github.com/bitrate16/ppa6-python/blob/main/n
196208

197209
* Fix page sometimes get cutted off for some rows
198210
* Fix delays
199-
* Python 2.7 support
211+
* ~~Python 2.7 support~~ (Don't need)
200212
* Implement overheat protection
201213
* Implement cover open handler
202-
* Tweak wait timings to precisely match the printing speed
214+
* Tweak wait timings to precisely match printing speed
203215
* Implement printer renaming
204216
* Implement printing stop operation
205217
* Reverse-engineer USB driver and add support for it
206-
* **FIX:** Print randomly gets cropped (some images getting cropped)
207-
* **FIX:** 1 type conversion is low quality
218+
* Print randomly gets cropped (some images getting cropped)
219+
* 1 type conversion is low quality
220+
221+
## Contribution
222+
223+
> Q: How to contribute?
224+
>
225+
> A: Implement some features and make a pull request in this repo. For example, you could add info about USB communication, write a any-font printing using PIL text drawing, make an additional research in protocol and other cool things.
226+
227+
> Q: How to get my printer supported?
228+
>
229+
> A: If you own a peripage printer that is currently unsupported, you can reverse-engineer the bluetooth packets captured from the oficial printing app and find out the specs of your printer (the main and the only spec is bytes per row). Another way is to find how many letters can fit in a row when using `printASCII()`.
230+
>
231+
> If you would like to participate, please make an issue and I will guide you on how to obtain required parameters.
208232
209233
## Credits
210234

211235
* [Elias Weingärtner](https://github.com/eliasweingaertner) for initial work in reverse-engineering bluetooth protocol
212236
* [bitrate16](https://github.com/bitrate16) for additional research and python module
237+
* [henryleonard](https://github.com/henryleonard) for specs of A40 printer
213238

214239
## Disclaimer
215240

@@ -223,4 +248,4 @@ SOFTWARE.**
223248

224249
## License
225250

226-
[MIT License](https://github.com/bitrate16/ppa6-python/blob/main/LICENSE)
251+
[MIT License](https://github.com/bitrate16/peripage-python/blob/main/LICENSE)

0 commit comments

Comments
 (0)