From 901ecd56b0bae912bd8dfda0f2b80787497db1d4 Mon Sep 17 00:00:00 2001 From: SeppPenner Date: Sat, 12 Sep 2020 15:31:46 +0200 Subject: [PATCH 1/2] Code style fixes, fixed bug with client (Using setInsecure to avoid bug with ESP8266 lib > 2.4.2). --- src/TelegramBot.cpp | 14 +++++++++----- src/TelegramKeyboard.h | 1 - 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/TelegramBot.cpp b/src/TelegramBot.cpp index c00846d..93b6e1b 100755 --- a/src/TelegramBot.cpp +++ b/src/TelegramBot.cpp @@ -12,10 +12,16 @@ TelegramBot::TelegramBot(const char* token, Client &client) { this->token=token; } - -void TelegramBot::begin() { +void TelegramBot::begin() { if(!client->connected()){ - client->connect(HOST, SSL_PORT); + client->setInsecure(); + + if(!client->connect(HOST, SSL_PORT)){ + Serial.println("Connection failed."); + } + else{ + Serial.println("Connected"); + } } } @@ -39,8 +45,6 @@ message TelegramBot::getUpdates() { StaticJsonBuffer jsonBuffer; JsonObject & root = jsonBuffer.parseObject(payload); - - if(root.success()){ int update_id = root["result"][0]["update_id"]; diff --git a/src/TelegramKeyboard.h b/src/TelegramKeyboard.h index 34e7dbc..fac1f92 100755 --- a/src/TelegramKeyboard.h +++ b/src/TelegramKeyboard.h @@ -4,7 +4,6 @@ // TelegramBot library // https://github.com/CasaJasmina/TelegramBot-Library - #ifndef TelegramKeyboard_h #define TelegramKeyboard_h #include From 8cd38342e215061caeb2c950a8733299132833b6 Mon Sep 17 00:00:00 2001 From: SeppPenner Date: Sat, 12 Sep 2020 17:56:03 +0200 Subject: [PATCH 2/2] Fixed smaller bug. --- src/TelegramBot.cpp | 2 +- src/TelegramBot.h | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/TelegramBot.cpp b/src/TelegramBot.cpp index 93b6e1b..06c3931 100755 --- a/src/TelegramBot.cpp +++ b/src/TelegramBot.cpp @@ -7,7 +7,7 @@ #include "TelegramBot.h" -TelegramBot::TelegramBot(const char* token, Client &client) { +TelegramBot::TelegramBot(const char* token, WiFiClientSecure &client) { this->client = &client; this->token=token; } diff --git a/src/TelegramBot.h b/src/TelegramBot.h index 1f56cf9..8397403 100755 --- a/src/TelegramBot.h +++ b/src/TelegramBot.h @@ -9,7 +9,7 @@ #include #include -#include +#include #include #define HOST "api.telegram.org" @@ -33,7 +33,7 @@ struct message{ class TelegramBot { public: - TelegramBot(const char* token, Client &client); + TelegramBot(const char* token, WiFiClientSecure &client); void begin(); String sendMessage(String chat_id, String text); String sendMessage(String chat_id, String text, TelegramKeyboard &keyboard_markup, bool one_time_keyboard = true, bool resize_keyboard = true); @@ -45,7 +45,7 @@ class TelegramBot const char* token; int last_message_recived; - Client *client; + WiFiClientSecure *client; }; #endif