Communicate with a telegram bot using https request through esp-idf

antusystem
Posts: 2
Joined: Thu Jan 07, 2021 2:48 am

Communicate with a telegram bot using https request through esp-idf

Postby antusystem » Thu Jan 07, 2021 3:03 am

Edit: I was able to communicate with a telegram bot, in here (https://github.com/antusystem/esp-idf-telegram-bot) is an example for that.

Hi, I'm trying to communicate to my telegram bot using the https_request example in the ESP-IDF. On the long road I want the ESP32 to send data to the bot, but now I'am just trying to communicate with it. I believe I understand how the example works so I made these changes:

Code: Select all

#define WEB_SERVER "https://api.telegram.org"
#define WEB_PORT "443"
#define WEB_URL "https://api.telegram.org/bot<your-bot-token>/getme"
The request from the example is:

Code: Select all

static const char *REQUEST = "GET " WEB_URL " HTTP/1.0\r\n"
   "Host: "WEB_SERVER"\r\n"
   "User-Agent: esp-idf/1.0 esp32\r\n"
   "\r\n";
It should respond something like:

Code: Select all

{'id': 123456789, 'first_name': 'Test', 'is_bot': True, 'username': 'Espressif', 'can_join_groups': True, 'can_read_all_group_messages': False, 'supports_inline_queries': True}
The error occurs in line 68, with esp_tls_conn_http_new:

Code: Select all

E (3110) esp-tls-mbedtls: mbedtls_ssl_handshake returned -0x2700
E (3120) esp-tls: Failed to open new connection
Note: I just notice the http_mbedtls example and https_x509_bundle example, but haven't use them.

Note 2: to learn about the example I used these defines and everything worked fine:

Code: Select all

#define WEB_SERVER "www.swapi.dev"
#define WEB_PORT "443"
#define WEB_URL "https://swapi.dev/api/people/1/"
Note 3: I have seen that some people use a certificate (like this https://github.com/witnessmenow/Univers ... tificate.h and this https://github.com/kenzanin/esp-idf-tel ... legram.pem) but I'am not sure what they are or how/when to use it, I believe it is something for https, but I'm not sure. But I believe this is the problem, the certificate.

Note 4: I'm trying now esp_http_client example to see if it work there, but until now I have found the same error when I use the function https_with_url with a little changes.

Thanks

Who is online

Users browsing this forum: MattWork and 69 guests