Closed NaitLee closed 2 years ago
This day I costed 10 hours investigating python-for-android, and bleak integration with it. It's a long process suffering from the dirty job made by those java developers, but I finally made it... My test python script successfully being compiled to an apk, installed on my phone, printed the pre-defined data. There are many, many hacks made for the work. Going to summarize these later. Well, let's see the final result...
@NaitLee in an other project we see CUPS as a good option https://github.com/rbaron/catprinter/issues/24
Hey, current version of this project has a very basic CUPS/IPP support π EDIT: no longer legacy-only. See newest pre-release for testing! Though, it's really very basic, and it can only receive printed content and print it, no further "status" at all.
server.py
.ipp://127.0.0.1:8095/
as a Generic PostScript Printer.
You can (not required) append string after the url, like GB02
or 61:06:ff:7d:8d:fd
, for picking the correct printer.gs
in Linux) for converting to PBM image format. Be sure to install it.Note: currently there is no error reporting mechanism. The way to do (via ipp protocol or cmdline) is not determined either.
CUPS/IPP is kinda complex. If it's going to be fully supported, around 80% of the code will be of that. You can see the IPP specification here. It's not something short after all.
Worthy to mention is that this project is different: it aims at a user interface, not just backend. So the desired user-friendliness is already on the Web interface, and thanks to Web you can actually copy-paste almost anything to it, then print.
I'm wondering if I should make all the stuffs (like "full" wysiwyg editing and stickers/borders etc) or just keep it simple. There are all editors around (libreoffice, gimp, inkscape, etc), while most of them are on PC. Some Android users will still feel "uncomfortable", though. I tried fabric.js and html2canvas previously, and I think making full use of them here have some chance of wasting the time. "A software should only do one thing, and do it well." But users won't take it serious. What a dilemma. I know I can't satisfy everyone, and that's a reason for me to make web interface, satisfying low-end poor users. I'll just do the basic now... Going to deal with these later...
I would love to see templates for barcodes, business cards, shopping lists and route information.
You mean a full interface π Well, after some thoughts I think I should switch the direction: just make a full featured Printer frontend, and let backends can integrate with it. And there are already many versions of backends across here, just let them expose some functions or a class, or I adapt them.
I'd tell the full reason later. But you need to understand the situation, of the dirty "intellectual property". In doubt? Read the EULA of iPrint app. (if have ability, read EULA of η²Ύεε¦δΉ the Chinese/original version.) I don't need to tell further if you spot the points. I did nothing wrong, but it's still too big risk for me a native person, and local users. Let's help Free Software, while keeping everyone well...
If it's possible, the addition of GB03
support would be nice - I haven't found any project compatible with that model yet, which is what I unknowingly ordered. For reference, here's a link to Amazon where the GB03
model was purchased.
Another differentiating factor I've noticed is that the iPrint
app has to be launched and printer chosen before the printer will show up in my phone's Bluetooth Devices menu. Despite all efforts, my Mac refuses to acknowledge the printer is broadcasting at all and refuses to list the device, even with an external BLE dongle.
From Free Software Is Even More Important Now:
... It also wrongs others if you make a promise not to share. It is evil to keep such a promise, and a lesser evil to break it; to be truly upright, you should not make the promise at all.
Fuck it up (β―βΊΠβΊ)β―οΈ΅ β»ββ» Let's do it.
$ jadx iprint.apk
I've found that in GB03 model the Bluetooth command buffer sent to printer is "compressed" with a small algorithm. Along with this there are some other things that different. EDIT: there's also an additional procedure for checking GB03. and the typos like data -> date suck It is really nothing to implement these shit, but we need a physical printer to check if it works. Amazon did a bad job for this, it's 2x-4x money to buy one. Completely NOT affordable for me. I've consulted local seller where I bought my GB02, they say they have no GB03. Compared to other, these printers are very cheap -- I bought one for around οΏ₯80 (\~$12.5), and now they've discounted to οΏ₯40 (\~$6) They have more than cat printers. In fact they have everything, and some printers are even AI compatible. That's a lot of work, if going to do all of them.
Also, to check what's up in BLE we need some special tools. I've found this. I bought a compatible dongle just now for οΏ₯60 (\~$10) but I suddenly think I have no idea to make use of it.
Sorry for the inconvenience, the biggest obstacle is money, and communication. I want anonymity for continuing further jobs, and of course users' collaboration of sharing/testing the printers... Any brave guy to provide such a solution? Totally unbelievable such a job turned to be on my head... πΆβπ«οΈ
... By the way the new frontend is going to be usable. Now it have better monochrome algorithm. Doing the finalization works... I think putting it on a new branch could be fine... π
I ordered a printer yesterday on AliExpress... I don't know which version it would be... But I think I will be brave enough for testing π
Oh crap, maybe that's the reason this is not working to me. I just bought a model and it seems to be GB03. How different is it from the older models?
I'm wondering if I could:
Well, the nRF52840 dongle I've bought have use now... π
In addition there's also a "canPrintLabel" stuff that happens in GB03's bitmap procedure. Along with compression and detection, it's very different...
In their code those Chinglish function names really suck. Give them some color to see see.
Sorry for the long wait, but it's finally released. You can test the 0.1.0 releases immediately, and play with the Android version!
At the moment there's few function. Going to do them later. The Android building how-to is not there yet. Patience... As for GB03, I'll take a look when I feel appropriate, with the bluetooth dongle hack. My C programming skill is not good enough, though... (doing with the dongle needs to write C/C++ firmware programs)
Oh still waiting for that GB03 update! :(
Well, just now I set up the bluetooth low energy development environment, modified an example code (a typical "blink" program on all IoT stuffs, but have bluetooth interface, I changed the broadcast name to "GB03" and BLE characteristic to the desired) and successfully fooled iprint to list my dongle π But I need real data transferring techniques, serial communication to dump the traffic, and some analytic tricks, will manage to do/learn all of them. Every day is a new progress π
BTW do you really hate "iprint"? I see it just-so-so. Yes it's big. My reason to do all of these is I hate the chinese version. It even wants my phone number. And everyone else's. Of course I fight for true freedom of worldwide π
BTW do you really hate "iprint"?
Oh yes I do. The whole point for me of getting this little printer is to be able to manage it on CLI and not install any fishy app on my phone. Thanks @NaitLee for all your work!
For CLI what you need is (currently) just printer.py
, and the Bleak dependencie.
I also concern about these, while I want to follow the Unix philosophy: do one thing and do it well.
That means it will not bother geeks to force many dependencies. But I also want normal users to enjoy it.
The script accepts a PBM image file, either with path to file or use stdin.
For other formats there's imagemagick, usually already there in GNU/Linux, simply do image manipulation with that (the convert
command) then pipe to printer.py
I once did that but lost the command parameters. It takes some time to get the correct parameters. Going to build it in later.
In the mean while there's actually a procedure for PBM generation in the Web frontend. You can modify the code of either side slightly to dump the result.
There is also GIMP for general image manipulation with GUI. It can export PBM as well.
A note: my script supports "dry run". You can test configuration with it without wasting paper!
I come up the idea to support "text printing", you enter the command line, then just type some text (or pipe to stdin!), and printer will print, in a "streaming" way.
For the same reason I want to use the PF2 font format, it's easy to make (use grub-mkfont
with a common ttf/otf font file), easy to support, Unicode compatible, and for it's bitmap font it can do the "typewriter" hack!
Also the current printer.py
is actually just a purged version of legacy version. There are many things to be changed.
Seems now I should put GB03 support on the top. Stay tuned!
Iβm absolutely tuned. My GB03 printer is still waiting to be used. Thanks again!
Hello guys, just got GB03 to print with latest release 0.1.0. easy as f### ! Also, thank you NaitLee for you work, it;s awesome! PS: I want to be a tester for GB03 printer.
I would like to say something now...
Yesterday I put the effort totally to the dongle hack, but I faced big problems:
uucp
group added) and will segfault at any time. No pin label to GPIO image/figure at all and I should brute test. And the JLink tool that says missing DLL on Linux. Last the document/manual all about the dirty license but nothing about how-to for the SDK code. Approx. 1/8 of all the 200MiB SDK C code is comment of their license. Nevermind.Of course I wanted to by another open ble thing that just works. But an idiot brought covid from shanghai to my county and everything messed up, express/delivery stopped and I can't buy any hardware or snacks now.
Too many bad things happened these days. What I can do is just hope everyone well π’
Today I have other work. If I want I would continue to try on a Windows VM. That's what those suckers love.
Okay, I just found Android itself is capable of BLE emulation. There's nRF Connect APP, going to use it on my another phone now rather than wasting time π
Hi guys, I managed to dump all the data between iprint and GB03 (and "original" GB02 for comparison), and analyze... but found maybe it's just a matter of a 0x12
byte.
Please test with the attached script below, by replacing the same file in a working 0.1.0 release with it.
I don't know if it will work yet. Please say...
EDIT: if it doesn't work, please also test if BLE Characteristic is a problem. In the code find & replace this:
0000ae01-0000-1000-8000-00805f9b34fb
with one of these. It's better to try all... especially the ae81
one:
0000ae81-0000-1000-8000-00805f9b34fb
0000ab01-0000-1000-8000-00805f9b34fb
0000ff02-0000-1000-8000-00805f9b34fb
49535343-8841-43f4-a8d4-ecbe34729bb3
Be verbosely, though I finally understood how it works, the GB03 "compress" procedure seems being optional, and actually have some chance to make data chunk bigger -- then iprint will rather just send that chunk in the old way, just like e.g. GB02.
But implementing it will be cool and save connection time... "Low Energy", right? π
Mathematics alert!
These are found with my eyes on a calculator (KCalc) with bit-mode. The original code is too messy...
(Semi-)Detailed statement of that compression:
Note: The "compressed" data is in a command 0xBF
rather than normal 0xA2
.
0
or all are 1
), to a maximum count of 1270
, if the chunk is full of 0
. Otherwise 1
.Okay, there maybe few mistakes... Let's check later...
Examples:
FF FF 00 00
: this is the old "uncompressed" format, that represents 16 black pixels and following 16 white pixels.
1111 1111 1111 1111 0000 0000 0000 0000
C0 40
: this is the "compressed" format, that represents 64 black pixels and following 64 white pixels.
1100 0000 0100 0000
. It's (somewhat) 8 times smaller! Taste the feeling πOh right, let me put the attachment now... Decompress it first... printer.zip
EDIT: In case you need frontend to work, also replace this, in the www
folder:
main.zip
Oh no, and also this, in the main folder... sorry for inconvenience...
server.zip
Hi guys, I managed to dump all the data between iprint and GB03 (and "original" GB02 for comparison), and analyze... but found maybe it's just a matter of a
0x12
byte. Please test with the attached script below, by replacing the same file in a working 0.1.0 release with it. I don't know if it will work yet. Please say...EDIT: if it doesn't work, please also test if BLE Characteristic is a problem. In the code find & replace this:
0000ae01-0000-1000-8000-00805f9b34fb
with one of these. It's better to try all... especially the
ae81
one:0000ae81-0000-1000-8000-00805f9b34fb 0000ab01-0000-1000-8000-00805f9b34fb 0000ff02-0000-1000-8000-00805f9b34fb 49535343-8841-43f4-a8d4-ecbe34729bb3
Be verbosely, though I finally understood how it works, the GB03 "compress" procedure seems being optional, and actually have some chance to make data chunk bigger -- then iprint will rather just send that chunk in the old way, just like e.g. GB02.
But implementing it will be cool and save connection time... "Low Energy", right? π
Mathematics alert! These are found with my eyes on a calculator (KCalc) with bit-mode. The original code is too messy... (Semi-)Detailed statement of that compression: Note: The "compressed" data is in a command
0xBF
rather than normal0xA2
.* While parsing bitmap, Pick next chunk of continuous bits, that have the same value (i.e. all are `0` or all are `1`), to a maximum count of 127 * If the chunk size is bigger than 16, do the following: * Take a number from 96, 64, 48, 32, 24, 16 (they can all modulus 384 to 0). Adapt the maximum but in the range of original size, except when size is above 96 then just use 96. * Divide 384 with the number, get another integer number. Put its value as the command parameter. * Allocate a byte, do this: * Make the **first bit** `0`, if the chunk is full of `0`. Otherwise `1`. * Let the other 7 bits be the size of this chunk. Of course maximum value is 127. * Do the same to the other bits... Until the payload is enough big. Put the result in the command payload. * If the chunk is too small, simply use the old format, that just regard a bit as a pixel. * Loop 'till end...
Okay, there maybe few mistakes... Let's check later...
Examples:
* HEX `FF FF 00 00`: this is the old "uncompressed" format, that represents 16 black pixels and following 16 white pixels. * Binary as `1111 1111 1111 1111 0000 0000 0000 0000` * HEX `C0 40`: this is the "compressed" format, that represents 64 black pixels and following 64 white pixels. * Binary as `1100 0000 0100 0000`. It's (somewhat) 8 times smaller! Taste the feeling π * Especially useful with text printing... There are many continuous white pixels there
Oh right, let me put the attachment now... Decompress it first... printer.zip .
I tested and is working... with some random disconnects but it's fine!
Hi @NaitLee
I have got my printer today... but I can not get the server.py working
all I see is
I can print via printer.py
any idea?
Hey, current version of this project has a very basic CUPS/IPP support smile You can see some related code at server.py. I just kept it secret for a long time... Though, it's really very basic, and it can only receive printed content and print it, no further "status" at all. EDIT: The newest commit is not released yet. To test the following please
git clone
the repo and get the dependencies (can just pick most from a release) It requires ghostscript being installed, and add theipp://127.0.0.1:8095/GB02
as a PostScript printer. (replace GB02 as your printer bluetooth name) It directly invokesgs
in the current shell. Be sure thegs
is notalias
-ed by some advanced shells togit status
... (if it happens, tryunalias gs
) Now just launchpython3 server.py
, enable bluetooth and open the printer. Try it with something like LibreOffice! Use an A4 portrait paper, and a bigger font (probably more than 32pt)CUPS/IPP is kinda complex. If it's going to be fully supported, around 80% of the code will be of that. You can see the IPP specification here. It's not something short after all.
Worthy to mention is that this project is different: it aims at a user interface, not just backend. So the desired user-friendliness is already on the Web interface, and thanks to Web you can actually copy-paste almost anything to it, then print. Going to make it better after all the main jobs, at least mimicking a stable just-work CUPS interface, if ya reilly want stuck_out_tongue_winking_eye
I did not get this working as well
Sorry for the inconvenience, the CUPS/IPP feature is in legacy, but not this new version yet. I updated the comment to make it clear.
As for frontend, check if that: a) you have an old browser, that doesn't support newer ecma script features, like firefox esr. and b) you are using the repo alone, without putting i18n script and/or transpiling a compatibility script (see the points in development.md), or c) you didn't enable javascript
anyway, press F12 in browser and see what's inside the console. you may try with a new browser and a published release (like 0.1.0)
d) VPN somehow
with one of these. It's better to try all... especially the
ae81
one:
It didn't work either. Still waiting for the support! Thanks again
It didn't work either. Still waiting for the support! Thanks again
Oh, no π’ Maybe I should check if iprint sent something during initialization... Just tough.
@claudioruiz did I get it... you have an none working GB03? I have a GB03 too... works great
@claudioruiz did I get it... you have an none working GB03? I have a GB03 too... works great
Yup, no luck at all even connecting the printer to the computer. It seems as the printer doesn't even exist for the computer (I did test it with my phone using nRF Connect and it's capable to find it). I can't use it so far :(
@claudiorrrr could you give me the output of lsusb | grep Bluetooth
@claudiorrrr could you give me the output of
lsusb | grep Bluetooth
lsusb | grep Bluetooth
shows no output on MacOS. Same with Ubuntu on a x220. :/
i remember bleak said macos is different in some cases. you can look into it in its document site... and the printer actually isn't a 'normal' bluetooth stuff. 'normal' connection doesn't work on it, and pairing does nothing useful. Bluetooth Low Energy should not be confused with 'normal' bluetooth though... you can know more on internet...
@claudiorrrr could you give me the output of
lsusb | grep Bluetooth
lsusb | grep Bluetooth
shows no output on MacOS. Same with Ubuntu on a x220. :/
Try to change usb to pci
@claudiorrrr could you give me the output of
lsusb | grep Bluetooth
lsusb | grep Bluetooth
shows no output on MacOS. Same with Ubuntu on a x220. :/Try to change usb to pci
same
I'm wondering if it's just problem of Mac. If could, you can try with a Linux VM in Mac. I recommend Virtualbox. It's easy to do basics. And I just mention that you need to attach the bluetooth adapter to VM in virtualbox (in my case it's called "Intel Corp." in USB devices selection), and to do this you likely need "virtualbox extension pack" installed first. In Linux env you can follow the readme to get work. Don't forget check the common myths like didn't enable bluetooth etc. The printer is able to be scanned & shown, but not able to be connected nor paired (with 'common' bluetooth protocol). usb cable does no work. I will publish a pre-release now, including current code, for testing... Still, feel free to ask any problems encountered π
I had the idea that the Bluetooth adapter isn't BLE capable... But it wasn't there as a USB or PCI device. So we can't really check that.
I had the idea that the Bluetooth adapter isn't BLE capable... But it wasn't there as a USB or PCI device. So we can't really check that.
Well, why not just test π My bluetooth adapter is built inside my computer, but still shown as USB device. Apple MacOS alike is "painful", said by many (at least) web developers, for it's lockdown nature. But Mac computer is yet expensive. I never wanted to waste money on such a stuff... π
And BLE have some concepts, thing like our printer is called "peripheral", and our computer is called "central" when it controls the printer.
My computer bluetooth adapter is not BLE peripheral compatible either (unsure), but it can communicate to printer! I can even see the traffic in Wireshark.
My cheap bluetooth earbuds are identified as BLE too. If there is AirPods, why isn't Mac computer BLE compatible π€«
Android phones can mostly do both, though just one at once. That's how I've dumped iprint traffic with 2 phones π
I will also put apk in the release, for also trying on android. Also in the pre-release there's cups/ipp. Try that, please π
It's a long time not updated this repo. Half years ago I got a laptop (now using) but it's not my development platform at that time, while I need bluetooth on it. So after a rush the code is very poor, in the sight from 2022 πΆβπ«οΈ
Now that I'm cleaning up the main python script while making a brand new frontend -- the earlier is done, now the later Going to commit them all together, because at the moment there's no actual difference at all. I'm also planing to host this project (also) to somewhere else. Here really have problems accessing GitHub.
I see python-for-android while investigating bleak (the bluetooth lib), found that I can build an working Android version with just what a PC version will have -- Python, basehttp, bleak, and a common web interface. This way we are all free from the original weird app... And, feel free to discuss what you guys really need in an "app" π
Emm, maybe the image monochrome filter needs enhancement as well...
Wish I'll complete this goal π