shurillu / CTBot

A simple (and easy to use) Arduino Telegram BOT Library for ESP8266/ESP32
MIT License
147 stars 34 forks source link

getNewMessage error: { "ok": false, "error_code": 502, "description": "Bad Gateway" } #46

Closed hamster66 closed 4 years ago

hamster66 commented 4 years ago

Hi. I get this error from only one of my bots. Other IDs still work fine. Through curl access to this bot is normal. Why could this happen and how to deal with it? Besides. Despite setting myBot.useDNS(true); I get message Connected using fixed IP Thank you in advance.

shurillu commented 4 years ago

Hello Hamster! Your issue sound like this one: #45, take a look. Long story short, it could be due to the new Telegram IP Server: 149.154.167.220. Try to change it in the CTBot.cpp file. Regarding the useDNS() method, it's a bit weird: the library fall back to the fixed IP when it's impossible to resolve the URL, maybe your DNS Server doesn't resolve the telegram URL (try to ping api.telegram.org). Lastly, you could try to use inside the ESP8266 an user defined DNS server (Cloudflare, for example) with the setIP(String ip, String gateway, String subnetMask, String dns1, String dns2 ) method (in this case, you have to define the IP, Gateway and subnet mask too).

Let me know if you find a solution! Cheers, Stefano

hamster66 commented 4 years ago

Sorry, but if I change it in the CTBot.cpp file:

 #define TELEGRAM_IP   "149.154.167.220"

everything generally stops working :(

Unable to connect to Telegram server getNewMessage error: response with no data

but if I ping from computer in this net:

# ping 149.154.167.220
PING 149.154.167.220 (149.154.167.220) 56(84) bytes of data.
64 bytes from 149.154.167.220: icmp_seq=1 ttl=56 time=44.5 ms
64 bytes from 149.154.167.220: icmp_seq=2 ttl=56 time=44.5 ms
64 bytes from 149.154.167.220: icmp_seq=3 ttl=56 time=44.4 ms
^C
--- 149.154.167.220 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2003ms
rtt min/avg/max/mdev = 44.431/44.471/44.514/0.033 ms
# ping api.telegram.org
PING api.telegram.org (149.154.167.220) 56(84) bytes of data.
64 bytes from 149.154.167.220 (149.154.167.220): icmp_seq=1 ttl=56 time=44.7 ms
64 bytes from 149.154.167.220 (149.154.167.220): icmp_seq=2 ttl=56 time=44.5 ms
64 bytes from 149.154.167.220 (149.154.167.220): icmp_seq=3 ttl=56 time=44.3 ms
^C
--- api.telegram.org ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2002ms
rtt min/avg/max/mdev = 44.304/44.491/44.669/0.149 ms
shurillu commented 4 years ago

How many times do you call the getNewMessage() method? In other words, is the method inside a loop (with a delay of 1 sec)? Sometimes the Telegram Server doesn't answer quickly, so the message. Try to run several calls (delayed by a second) and let me know

Stefano

hamster66 commented 4 years ago

I call once on 3 sec in loop. And if IP is 149.154.167.198 all works good except one of my bots.

hamster66 commented 4 years ago

OK!!! New IP works if compile with All SSL chipers options.