0

Edit: I realize that the problem was with the certificate and I was not able to add it to this example. I switch to the esp_http_client, which has a certificate (that did not work for telegram), and in there I use the https examples. I had to change the certificate for it to work, I use the one is used in Universal Telegram Bot for Arduino, and then I was able to communicate with the page via GET, I'm trying to use POST now.

Edit 2: I was able to send the POST request. Here I let the example to communicate with a telegram bot.

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:

#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:

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:

{'id': 123456789, 'first_name': 'Test', 'is_bot': True, 'username': 'SlackOverflow', '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:

E (3110) esp-tls-mbedtls: mbedtls_ssl_handshake returned -0x2700
E (3120) esp-tls: Failed to open new connection

Note: I just find this example that does HTTPS GET using plain mbedTLS sockets, but don't know if it differs a lot from the example I used.

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

#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 and this) 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.

Thanks.

  • do they use TLS 1.2? – Juraj Jan 06 '21 at 17:54
  • I search and according to an answer in the esp32 forum, here, yes, ESP-IDF supports it. In the official documentation I did not find which version they support Edit: I did make menuconfig in the project and confirmed that it has compatibility with TLS 1.2 – antusystem Jan 07 '21 at 01:50
  • Did you include the certificate of the telegram server? I've sucessfully connected to the telegram about a year ago, also based on the same example, I believe. Needed to change the URL but also embed the certificate into the application. The example application mentions this somewhere in the README or the code documentation. – StrawHat Jan 08 '21 at 04:14
  • With the https_resquest example I could't add that certificate, I did not find how to do it. I switched to the esp_http_client example and I had the same problem, but they had a certificate there, so I just change the content to the telegram's server certificate (one I found in the Universal Telegram Bot for Arduino because I did't know where to find it) and I was able to send Get resquest. I'm learning now how to send POST request. How did you add the certificate of the telegram server on the https_request example? – antusystem Jan 08 '21 at 15:16
  • I'm at work, so don't have the code I used at hand. I think I just used the `examples/protocols/esp_http_client` example. I'll check this tonight if I remember... – StrawHat Jan 11 '21 at 04:20
  • Thanks. With that example, today, I was able to send both GET and POST request to the telegram server, the json was stoping me using POST. Either way, would like to see how did you do it if you are so kind of passing your code later :). Thanks – antusystem Jan 12 '21 at 01:35

0 Answers0