Giter Club home page Giter Club logo

Comments (11)

witnessmenow avatar witnessmenow commented on September 15, 2024

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.

NDscham avatar NDscham commented on September 15, 2024

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.

witnessmenow avatar witnessmenow commented on September 15, 2024

from universal-arduino-telegram-bot.

NDscham avatar NDscham commented on September 15, 2024

Awesome, thanks! I could look into it as well, although I am not really familiar with JSON.

from universal-arduino-telegram-bot.

karonth avatar karonth commented on September 15, 2024

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.

denzen84 avatar denzen84 commented on September 15, 2024

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.

efeuentertainment avatar efeuentertainment commented on September 15, 2024

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.

springm avatar springm commented on September 15, 2024

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.

springm avatar springm commented on September 15, 2024

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.

witnessmenow avatar witnessmenow commented on September 15, 2024

from universal-arduino-telegram-bot.

ema800 avatar ema800 commented on September 15, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.