micropython-utelegram icon indicating copy to clipboard operation
micropython-utelegram copied to clipboard

Problems with ESP12F

Open boinjoe opened this issue 5 years ago • 6 comments

Thanks for this nice library. I’ve tried it on ESP32 and it works well. But with ESP12F (ESP8266) it’s not working. No idea if where is the problem.

boinjoe avatar Jan 01 '21 18:01 boinjoe

i've tried it on the ESP8266 as well, but it doesn't work there, no clue why

Benemenn avatar Jan 23 '21 08:01 Benemenn

Can you provide a sample app that's not working if it produces any relevant error message?

Thanks,

jordiprats avatar Jan 23 '21 14:01 jordiprats

Hi, Nice Library :-) I also have tested your library in a ESP8266 (Wemos Lolin D1 Mini Pro) and unfortunately it does not work. I tested your demo project and it returns BOT LISTENING in the terminal but it does not react to a /ping message. I also tested to send a message with

bot.send('CHAT_ID', 'Bot started...')

But no response on Telegram. I also checked the Wifi connection with sta_if.ifconfig() and looks good, so no connection problems. I get the following error on the first start of the code:

  File "main.py", line 5, in <module>
  File "utelegram.py", line 4, in <module>
  File "urequests.py", line 181, in <module>
KeyboardInterrupt: 

I have seen in your utelegram.py you are using the urequests and I suppose it has to do with following error from the urequests together with the telegram API. This error can be replicated with following code:

import urequests

def do_connect():
    import network
    wlan = network.WLAN(network.STA_IF)
    wlan.active(True)
    if not wlan.isconnected():
        print('connecting to network...')
        wlan.connect('SSID', 'WIFI_PASSWORD')
        while not wlan.isconnected():
            pass
    print('network config:', wlan.ifconfig())

do_connect()

msg = "Testmessage"
token = "XXXXXXXXXX:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
user_id = "XXXXXXXXXX"
urequests.get(f'https://api.telegram.org/bot{token}/sendMessage?text={msg}&chat_id={user_id}')

And returns following error:

Traceback (most recent call last):
  File "main.py", line 20, in <module>
  File "urequests.py", line 162, in get
  File "urequests.py", line 104, in request
OSError: -40
MicroPython v1.13 on 2020-09-11; ESP module with ESP8266

I have tried to find a solution but I have no clue.... Unfortunately I have no ESP32 on hand to try your code so I suppose this urequests error is only appearing on ESP8622 with the Telegram API, because using urequests.get("https://www.google.com") gets a valid reply...

Maybe this helps with solving the error. Cheers:)

smc8050 avatar Jan 31 '21 13:01 smc8050

Hi, With the latest merge we are explicitly freeing the urequests objects once they are no longer needed. I believe this could have been your issue. Could you please give it a try?

jordiprats avatar Apr 24 '21 07:04 jordiprats

OSError: -40 on ESP 8266 (ESP01). very strange to work on esp32 and not on esp8266

joaomede avatar Jun 20 '22 22:06 joaomede

OSError: -40 on ESP 8266 (ESP01). very strange to work on esp32 and not on esp8266

This might be related to a ESP8266 specific TLS problem other urequests users (like me) encounter

https://github.com/micropython/micropython/issues/3198#issuecomment-313856270 https://github.com/micropython/micropython-lib/issues/400#issuecomment-843416279

ghost avatar Jul 26 '22 16:07 ghost