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

No message received with Code similar to Echo example #35

Open
cschuhknecht opened this issue Jun 6, 2020 · 3 comments · May be fixed by #37
Open

No message received with Code similar to Echo example #35

cschuhknecht opened this issue Jun 6, 2020 · 3 comments · May be fixed by #37

Comments

@cschuhknecht
Copy link

Hi there, I need some help. I've coded something thats very similar to the Echo example. The only major thing i changed is that i send a custom message as soon as the ESP gets power.
I checked the IDs and stuff multiple times.
Here is the code:

#include <TelegramBot.h>
#include <ESP8266WiFi.h>
#include <WiFiClientSecure.h>

//------- WiFi Settings -------
const char* ssid = "epiCS-AP";
const char* password = "Password";

// ------- Telegram config --------
const char BotToken[] = "Token";

const char chat_id[] = "ID";

// SSL client
WiFiClientSecure net_ssl;
TelegramBot bot (BotToken, net_ssl);

void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
while(!Serial)

// Attempt to connect to Wifi network:
Serial.print("Connecting Wifi: ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
Serial.print(".");
delay(500);
}
Serial.println("");
Serial.println("WiFi connected");

bot.begin();
Serial.println("START");
}

void loop() {
Serial.println("ALERT");
delay(2000);
Serial.println("STILL ALERT");

String message = "EINSATZ!";
if(bot.sendMessage(chat_id, message)){
Serial.println("TELEGRAM Successfully sent");
}
else{
Serial.println("TELEGRAM NOT Successfully sent");
}

delay(300000);
}

And here is the Serial output:
epiCS-AP
..................
WiFi connected
START
ALERT
STILL ALERT
TELEGRAM Successfully sent

I don't understand why it doesn't work, but maybe you have a clue.

@SeppPenner
Copy link

SeppPenner commented Sep 12, 2020

I guess, I found the problem(s).

First of all, #32 needs to get merged as ArduinoJson 6 has changes made that are not compatible with ArduinoJson 5.

Secondly, the client just doesn't connect:

If you change the following lines in TelegramBot.cpp

void TelegramBot::begin() {
    if(!client->connected()) {
        client->connect(HOST, SSL_PORT);
    }
}

to

void TelegramBot::begin() {
    if(!client->connected()) {
        if(client->connect(HOST, SSL_PORT)) {
            Serial.println("Connected");
        }
        else {
            Serial.println("Connection failed");
        }
    }
}

you will see that the connection always fails. I just still have no idea why this happens...

P.S. Link to the client documentation: https://www.arduino.cc/en/Reference/EthernetClient

I will post updates here once I find out more...

@SeppPenner
Copy link

I guess, that Telegram has changed something in their API and that the library (or the Client.h library) can't handle TLS...

@SeppPenner
Copy link

SeppPenner commented Sep 12, 2020

@epiCS97
I found the issue... We need to set client.setInsecure(); before connecting when on ESP8266 library > 2.4.2 as there is some bug...

References: schlingensiepen/TelegramBotClient#6 and witnessmenow/Universal-Arduino-Telegram-Bot#104...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants