The telegram bot api should be queried for updates by using Long Polling (if WebHooks are not available).
Current Behavior
Currently, the binding uses ordinary polling and checks for updates every 100ms.
Possible Solution
When setting the listener for updates, the timeout for the GetUpdates() request must be specified explicitly as follows in TelegramHandler.java:
154 TelegramBot localBot = bot = new TelegramBot.Builder(botToken).okHttpClient(botLibClient).build();
155 localBot.setUpdatesListener(updates -> {
156 cancelThingOnlineStatusJob();
157 updateStatus(ThingStatus.ONLINE);
158 for (Update update : updates) {
........
239 }
240 }, new GetUpdates().timeout(60));
The current code does not specify the second parameter for setUpdatesListener(...), which results in generation of a default GetUpdates() object with a timeout set to 0. Timeout here is the actual time to wait for a response before returning. This is the waiting time for Long Polling.
Since my ISP seems to terminate a pending request after 50 seconds anyway, specifying 60 seconds here is plenty in my case.
It would be great if this would be configurable from the Paper UI. Maybe this also makes sense for the connection and read timeouts.
Steps to Reproduce (for Bugs)
Execute
tcpdump -i eth0 -A port 443
(check eth0 for correctness) and you will see lots of polling at 149.154.167.220 (telegram bot api)
Context
Regular polling results in huge amounts of idle traffic, which is particularly bad when using a mobile connection to the internet. In my case, the idle traffic was about 40-50 MB per day. This could be much worse if your mobile provider accounts for a minimum data packet length of 100k instead of 10k, for example.
Your Environment
Version used: openhab2 2.5.2-1, openhab2-addons 2.5.2-1
Environment name and version: Java 8
Operating System and version (desktop or mobile, Windows 10, Raspbian Buster, ...): Raspbian stretch
Expected Behavior
The telegram bot api should be queried for updates by using Long Polling (if WebHooks are not available).
Current Behavior
Currently, the binding uses ordinary polling and checks for updates every 100ms.
Possible Solution
When setting the listener for updates, the timeout for the GetUpdates() request must be specified explicitly as follows in TelegramHandler.java:
The current code does not specify the second parameter for setUpdatesListener(...), which results in generation of a default GetUpdates() object with a timeout set to 0. Timeout here is the actual time to wait for a response before returning. This is the waiting time for Long Polling.
Since my ISP seems to terminate a pending request after 50 seconds anyway, specifying 60 seconds here is plenty in my case.
It would be great if this would be configurable from the Paper UI. Maybe this also makes sense for the connection and read timeouts.
Steps to Reproduce (for Bugs)
Execute
(check eth0 for correctness) and you will see lots of polling at 149.154.167.220 (telegram bot api)
Context
Regular polling results in huge amounts of idle traffic, which is particularly bad when using a mobile connection to the internet. In my case, the idle traffic was about 40-50 MB per day. This could be much worse if your mobile provider accounts for a minimum data packet length of 100k instead of 10k, for example.
Your Environment