DIY

TelegaGraph. Printing messages and photos from telegrams to a thermal printer

TelegaGraph Printing messages and photos from telegrams to the thermal printer

I recently moved my TelegaGraph project on esp32. On esp8266, the code worked, but there were often glitches due to lack of memory, it was necessary to rebuild the firmware of the micropiton – in general, not a fountain. What my TelegaGraph lacked was printing photos to a thermal printer from messages. And now the day has come.
Of course, despite using a more powerful microcontroller, the miracle cannot happen. A photo from a phone will not even physically fit into the microcontroller's memory, let alone process it. Therefore, I had to write a small script in Flask, and upload it to PythonAnywhere, thereby shifting the downloading and processing of the photo onto it. The algorithm is simple: when the bot receives a message containing a photo, it sends a request to the site where my script is running, the script receives a photo (by file_id), crops it to the desired size (the printer needs 384 pixels wide), draws the text into the photo, converts it to h/b and sends back to the microcontroller in the form of bytes. The microcontroller saves the received bytes of the photo to a file and prints it to the printer. That's all the magic.
So, if you built TelegaGraph, then you do not need to make changes in the connection. You just need to update the code in the microcontroller. The project code is located in the same repository on GitHub. Also, in this repository in the www folder are files that will need to be placed on hosting on the Internet. I use PythonAnywhere because it's free. I will not explain here how to run a Flask application on this hosting, since this is not the article. There is nothing complicated, though the whole site is in English.
In the main.py file you need to specify the address of the site where you placed the script for processing the photo from the www folder. If everything is done correctly, then now your TelegaGraph will print the photo!
At the moment I have not completely figured out the print settings on the printer, so the photos are printed dimly and the text may not be visible. If anyone can tell you which parameters are correct – write, it will be great.

Source:

usamodelkina.ru

Show More

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button