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

ESP32 core 2.0.2 does not work (2.0.1 does) #270

Closed
javic-elec opened this issue Dec 23, 2021 · 5 comments
Closed

ESP32 core 2.0.2 does not work (2.0.1 does) #270

javic-elec opened this issue Dec 23, 2021 · 5 comments

Comments

@javic-elec
Copy link

Hi,

So I was testing my Telegram bot code after a long time since the last time I used it. I updated the ESP32 core to 2.0.2 (how lucky, just released 10 hours ago...), the UniversalTelegramBot to 1.3.0 and the ArduinoJson to 6.18.5. Testing either example codes or my own code, the bot just manages to send one message, but not more. It always gets stuck after the first sent message.

I have spent nearly an hour trying to figure out what was the problem, I even tried creating a new bot. As a last option, I just downgraded the ESP32 core to 2.0.1 and it worked perfectly.

So, if someone just runs with the same issue, downgrade to ESP32 core 2.0.1 (or just don't update it). I hope I can save someone's time.

Cheers.

@ndaneil
Copy link

ndaneil commented Dec 25, 2021

This issue seems to be that somehow, the ssl handshake timeout is set to 0 after the first message.
A temporary fix that worked for me was to change line 266 in the ssl_client.cpp (in the WiFiClientSecure library) file from:
if((millis()-handshake_start_time)>ssl_client->handshake_timeout)
to:
if((millis()-handshake_start_time)>(ssl_client->handshake_timeout != 0?ssl_client->handshake_timeout:120000))
(So I manually set a timeout if the handshake_timeout is zero.)

@jameszah
Copy link

jameszah commented Jan 2, 2022

I ran into this problem, and came with my work-around, which was to keep the channel open by deleting this line (at the cost of memory perhaps)

client->stop();

But then I saw @ndaneil comment .... and added to it. Rather than dig into ssl_client.cpp, you can add this line before the client->connect in the library.

    client -> setHandshakeTimeout(120000); 
    int x = client->connect(HOST, SSL_PORT);

You would have to add that setHandshakeTimeout before every one of these lines:

if (!client->connect(HOST, SSL_PORT)) {

The 120000 is milli-seconds or ??? But it comes from this source:

https://github.com/espressif/arduino-esp32/blob/master/libraries/WiFiClientSecure/src/WiFiClientSecure.cpp

sslclient->handshake_timeout = 120000;

You might also have to make this change to stop using Client and switch everything to WiFiClientSecure to get access to these calls (in the .h and .cpp)

  UniversalTelegramBot(String token, WiFiClientSecure &client);
 //UniversalTelegramBot(String token, Client &client);

@jameszah
Copy link

jameszah commented Jan 3, 2022

This is a simpler solution / work-around.
You still have to replace Cliient.h with WiFiClientSecure.h

Did you post this bug over in esp32-arduino issues?

void UniversalTelegramBot::closeClient() {
  if (client->connected()) {
#ifdef _debug
    Serial.println(F("Closing client"));
#endif
    client->stop();
    client -> setHandshakeTimeout(120000);
  }
}

@ndaneil
Copy link

ndaneil commented Jan 3, 2022

I found an open issue with the problem in the esp32-arduino repo:
espressif/arduino-esp32#6077

@witnessmenow
Copy link
Owner

witnessmenow commented Jan 4, 2022 via email

jameszah added a commit to jameszah/ESP32-CAM-Video-Telegram that referenced this issue Jan 18, 2022
Jan 18, 2022 ver 8.9  
  - updates from Arduino 1.8.19 
    - return from void problem re-runs the function if you dont do a return ???
      https://stackoverflow.com/questions/22742581/warning-control-reaches-end-of-non-void-function-wreturn-type
  - updates for esp32-arduino 2.0.2
    - bug with 2.0.2 handshake timeout - added timeout resets in this file as a workaround
      witnessmenow/Universal-Arduino-Telegram-Bot#270 (comment)
   - updates for esp32-arduino 2.0.2
     - esp-camera seems to have changed to fill all free fb buffers in sequence, so must empty them to get a snapshot
jameszah added a commit to jameszah/ESP32-CAM-Video-Telegram that referenced this issue Jan 18, 2022
Jan 18, 2022 ver 8.9  
  - updates from Arduino 1.8.19 
    - return from void problem re-runs the function if you dont do a return ???
      https://stackoverflow.com/questions/22742581/warning-control-reaches-end-of-non-void-function-wreturn-type
  - updates for esp32-arduino 2.0.2
    - bug with 2.0.2 handshake timeout - added timeout resets in this file as a workaround
      witnessmenow/Universal-Arduino-Telegram-Bot#270 (comment)
   - updates for esp32-arduino 2.0.2
     - esp-camera seems to have changed to fill all free fb buffers in sequence, so must empty them to get a snapshot
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants