Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use advantage of Telegram's POLL mode in func "getUpdate" to provide more efficiency #53

Open
denzen84 opened this issue Oct 12, 2017 · 4 comments
Labels
Milestone

Comments

@denzen84
Copy link

denzen84 commented Oct 12, 2017

Hi,

I use this bot through mobile 3G connection and I found that it eats a lot of mobile traffic.
I investigated this misadvantage and found the solution.

Telegram provides POLL mode of the connection. We should use special option in the query to say how long we can wait for the data. In current release bot sends update query every 1 second and immediately gets back empty message. To solve it, I modified the code of bot:

  1. In header "UniversalTelegramBot.h" add new definition "#define POLL_TIME_WAIT 60 // seconds"
    Higher value is better for traffic economy

  2. In source "UniversalTelegramBot.cpp" add some modifications:

  • function UniversalTelegramBot::sendGetToTelegram(String command):
    main loop:
    while (millis() - now < (POLL_TIME_WAIT*1000+1000)) {....}

  • function UniversalTelegramBot::getUpdates(long offset)
    String command = "bot"+_token+"/getUpdates?offset="+String(offset)+"&limit="+String(HANDLE_MESSAGES)+"&timeout="+string(POLL_TIME_WAIT);

I successfully tested these code improvements.

Thanks for your attention.

P.S. I'm too lazy to make new fork.

P.P.S. Telegram answers empty after 50 seconds wait. It means, that maximum value for POLL_TIME_WAIT is 50 secs

@denzen84
Copy link
Author

src.zip

@witnessmenow
Copy link
Owner

Available in the V1.1.0 RC branch

https://github.com/witnessmenow/Universal-Arduino-Telegram-Bot/tree/V1.1.0

@denzen84
Copy link
Author

IMHO default value for POLL should be 5-20 seconds.
IMHO ~1Gb of spurious traffic every month for each ESP where this bot installed is very expensive for the World. Think about green trees and nature pollution.

@witnessmenow
Copy link
Owner

witnessmenow commented Oct 17, 2017 via email

@witnessmenow witnessmenow mentioned this issue Oct 17, 2017
@witnessmenow witnessmenow added this to the V1.1.0 milestone Jan 26, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants