Page 1 of 1

TelegaGraph

Posted: Sun Mar 25, 2018 3:11 pm
by Lepeshka
TelegaGraph prints messages from Telegram Bot on a thermal printer only with ESP8266.

It is only the first version. The code is not the best, but I would like to have something to work. Used board Wemos D1 mini firmware Micropython v.1.9.3

I wrote a basic library for working with bot api Telegram. It can only send and receive messages. At the moment, sending of the message is very limited, in view of the need to complete the URL character encoding function.

For the thermal printer was also written a library, which implements only a small functionality. This library also requires improvements. For example, you need to add a function that will turn the printer into low-energy mode so that it does not discharge the battery so quickly.

To connect the printer to the microcontroller, UART1 was used, which is located on GPIO2 (D4). This UART, as I understand it, has only TX pins. I did not go to hell with UART0, because one-way transmission is enough for me. I sacrifice only the status functions of the printer, for example, I can not find out that the paper is over.

GitHub: https://github.com/Lepeshka92/TelegaGraph
Youtube: https://www.youtube.com/watch?v=bRStFu05Uio

Re: TelegaGraph

Posted: Mon Mar 26, 2018 6:13 am
by pythoncoder
I like it :D I wonder if there's scope for saving power by switching off the DC supply to the printer until a message arrives?

Re: TelegaGraph

Posted: Mon Mar 26, 2018 8:24 am
by Lepeshka
pythoncoder wrote:
Mon Mar 26, 2018 6:13 am
I like it :D I wonder if there's scope for saving power by switching off the DC supply to the printer until a message arrives?
Printer can be put into energy-saving mode until arrival of a new message

Re: TelegaGraph

Posted: Fri Feb 01, 2019 7:04 pm
by newb
Hi,

I'm trying ti get this thermal printer working but I fail to get the right codepage conversion.
I think the key is converting the UTF-8 bytearray into a codepage the printer recognises. Here is a self-test printout showing the active codepage iso-8852-5 along with the charset table.
codepage.jpg
codepage.jpg (165.64 KiB) Viewed 1440 times
I try to pass via uart.write() to the printer following string "АБВГ". As it's utf-8, I need to convert it to the printer active codepage. I'm trying with:

Code: Select all

bytes('АБВГ', 'ISO-8852-5')
and the result is "\xd0\x90\xd0\x91\xd0\x92\xd0\x93"

May be I'm using he docs in a wrong way? Here's the source: https://docs.micropython.org/en/latest/ ... html#bytes

However if I manually find the bytes in the charset (see printout above):

"\xb0\xb1\xb2\xb3"

and pass it to the printer on the UART, it prints the correct characters. This makes me think that the conversion function is wrong.
Any ideas why?

Re: TelegaGraph

Posted: Tue Feb 19, 2019 8:35 pm
by d4ß
hey,

is it possible to get a general usable api.py?
I would like to use it for communication with some simple sensors on a ESP8266 (NodeMCU) in the long term, but first it seems to make sense to just understand what is going one.
I have no clue what is happening in this part of

Code: Select all

    def update(self):
        url = self._url + '/getUpdates?timeout=30&limit=1&offset=' + \
              str(self.offset)
        try:
            r = requests.get(url)
            jo = json.loads(r.text)
        except:
            return None

        if len(jo['result']) > 0:
            self.offset = jo['result'][0]['update_id'] + 1
            if 'message' in jo['result'][0]:
                if 'text' in jo['result'][0]['message']:
                    return (jo['result'][0]['message']['chat']['id'],
                            str(jo['result'][0]['message']['from']['first_name']),
                            str(jo['result'][0]['message']['text']),
                            jo['result'][0]['message']['date'])
        return None

    def listen(self, handler):
        while True:
            message = self.update()
            if message:
		handler(message)
Lepeshka's Code.

So removed it and its running (surprisingly) with a basic main.py

Code: Select all

import api

telegram = api.TelegramBot('token')

telegram.send('ChatID','Send me Message')
But than I get a
TLS buffer overflow, record size: 5165 (+5)
ssl_handshake_status: -257
False
Error, which means there is not enough RAM, ok. But why.
How Lepeshka can run the thermal printer driver and the bot without running out of memory.
Maybe somebody can simplify Lepeshka's code to an understandable level.

Thanks

Re: TelegaGraph

Posted: Tue Mar 26, 2019 2:38 pm
by kipsate
Heyy, I'm creating a small telegram bot library myself, and came here because I ran into the same problem, but figured it out eventually. As Damien pointed out here: https://github.com/micropython/micropyt ... -323631697 , the problem is that the default buffer size on the esp8266 is too small.

You can easily change it by compiling your own version on the firmware. You need to go to the makefile, line 8 and change -RT_EXTRA to a larger number like 5120 and recompile the firmware, then it will work.

Re: TelegaGraph

Posted: Thu Apr 18, 2019 11:45 am
by John da Silva
As correctly indicated by kipsate firmware change is required as was indiacted by dpgeorge on github (https://github.com/micropython/micropyt ... -323631697)

This following youtube video will help you get setup so that you can make changes to firmware ....
https://www.youtube.com/watch?v=jG7WBY_vmpE

I can confirm that I got Telegram working on a esp8266EX with flash size 4MB

Re: TelegaGraph

Posted: Sat Jul 13, 2019 8:47 pm
by d4ß
Dear kipsate and John da Silva,
hearing that is kind of sad.
I am okish (but not even close to perfect) at doing the hardware (eg. soldering, crafting, ...), but I really suck at programming (never actually learned it properly + no natural talent) and the prospect to bustle around with git stuff and/or compiling my "own" firmware is sort of repelling.
Can I bypass this buffer shortage by just using a ESP32 board with the official uPython firmware? Or is the small buffersize a general micropython limitation?

Thanks.