Comments (11)
Thanks for raising the issue.
Interesting solution to the problem, but you could not guarantee you would be at that level in the jsonArray.
Maybe counting the { versus the } would be one way to figure it out.
I think the max message length can be bumped much higher than it is. I made a call to the reddit api before on the esp8266 and it could handle a much longer response than that.
from universal-arduino-telegram-bot.
Increasing the JsonBuffer length increases processing time, which might be undesirable. I absolutely agree forcibly terminating a message is not the best solution (and the way I did it is unflexible), but it's probably better than an infite loop or skipping this message (by incrementing message_id).
Dynamically counting/closing the Array is probably better. Note, that there are {} and [].
from universal-arduino-telegram-bot.
from universal-arduino-telegram-bot.
Awesome, thanks! I could look into it as well, although I am not really familiar with JSON.
from universal-arduino-telegram-bot.
One possible solution to these problems is to return -1 as the message number in case the json decoding fails. If you do a getUpdates?offset=-1 it'll flush the queue skipping the message.
The problem with raising the buffer size is that'll be always a message that's bigger...so it won't be a complete solution. In many applications loosing a message is better than an infinite loop.
from universal-arduino-telegram-bot.
Probably I found solution.
Function int UniversalTelegramBot::getUpdates(long offset)
in some cases returns undefined result due to bug.
As you see, the last return might never called.
if (response != "") { // ..................... code here return 0; } }
from universal-arduino-telegram-bot.
i've experienced a similar loop.
i'm unsure if this is the same issue as @NDscham described.
when my esp8266 tries to send a long message, he sends the same message about 5 times.
after sendMessage(), the printed "response" was cut. only the last ~100-300 characters of the response were received/printed. and thus checkForOkResponse()
failed to find {"ok":true
this resulted in a loop inside sendPostMessage()
which sends the same message about 5 times.
basically this code inside sendPostMessage()
:
while (millis() < sttime+8000) { // loop for a while to send the message
[...]
sent = checkForOkResponse(response);
if (sent) {
break;
}
}
i don't know why "response" gets cut.
and a possible fix could be to automatically split long messages into multiple smaller ones, but that's not the best solution i believe.
from universal-arduino-telegram-bot.
I would love to see an automatic cut at the defined maximum message length very much.
I use the library for simple automation tasks, but recently got spammed by - I guess - other bots and due to my lack of skill to skip those messages, my program didn't work any more until I increased the maximum message size and read all those unwanted messages to clear the message queue
from universal-arduino-telegram-bot.
And thinking it further, a flushMessageQueue action would be useful - I'd call it after boot to make sure my Arduino can start with a clean slate. Unfortunately I am no C-Programmer, otherwise I'd try to implement it myself
from universal-arduino-telegram-bot.
from universal-arduino-telegram-bot.
@springm To automatic prevent infinite loop, in UniversalTelegramBot.cpp
if you modify UniversalTelegramBot::getUpdates
adding:
if (response.length() >= maxMessageLength) {
last_message_received = -2;
closeClient();
return 0;
}
In the next bot.getUpdates()
since are you going to add +1 to bot.last_message_received
variable that is set to -2, it will become equal to -1. When the update_id is -1 Telegram server returns the last message received. So if there is another message after the long one, then it will read it instead of get stuck in infinite loop.
from universal-arduino-telegram-bot.
Related Issues (20)
- write / respond to a group HOT 9
- Retrieving time HOT 4
- Soft watchdog randomly occurs
- how to solve it.. i try compile program using UniversalTelegramBot and than error HOT 1
- Bug in SoftwareSerial.h in version 3.1.2
- datatype difference : last_message_received (long) and update_id (int) HOT 5
- Sending messages should return the msg_id or there should be a method to get last_sent_msg_id
- EMOJIS HOT 1
- arduino uno r4 wifi weirdly stucks after a couple of hours HOT 2
- sendMultipartFormData not sending HOT 3
- ArduinoJson 7 - DynamicJsonDocument is deprecated HOT 2
- "highlighted" or link messages to telegram HOT 1
- Set a String in void setup and paste it into the object
- Telegram Wifi Thermostat software restart
- /delete
- ElementProxy.hpp not found
- Telegram WebApp, if (message.containsKey("web_app_data")) { HOT 2
- Telegram bot and seeedstudio wio terminal
- Enabling Debugging Without Modifying the Library
- UniversalTelegramBot.h: error compiling in Arduino IDE.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from universal-arduino-telegram-bot.