https request failed

axel_hpplt
Posts: 7
Joined: Thu Aug 26, 2021 8:57 pm

https request failed

Postby axel_hpplt » Tue Sep 07, 2021 1:21 am

Hello everyone,

When I run this code :
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include "esp_system.h"
  4. #include "esp_console.h"
  5. #include "esp_vfs_dev.h"
  6. #include "esp_vfs_fat.h"
  7. #include "esp_wifi.h"
  8. #include "driver/uart.h"
  9. #include "nvs_flash.h"
  10. #include "esp_http_client.h"
  11.  
  12. #define EXAMPLE_ESP_WIFI_SSID "iPhone"
  13. #define EXAMPLE_ESP_WIFI_PASS "XXXXXXXXXXXX"
  14.  
  15. void app_main(void)
  16. {  
  17.     char dest[100] = "https://XXXXXXXXXXXXXXXXX.com/connect.php?texte=";
  18.     setvbuf(stdin, NULL, _IONBF, 0);
  19.     setvbuf(stdout, NULL, _IONBF, 0);
  20.     ESP_ERROR_CHECK(uart_driver_install(CONFIG_ESP_CONSOLE_UART_NUM, 256, 0, 0, NULL, 0));
  21.     esp_vfs_dev_uart_use_driver(CONFIG_ESP_CONSOLE_UART_NUM);
  22.     esp_vfs_dev_uart_port_set_rx_line_endings(CONFIG_ESP_CONSOLE_UART_NUM, ESP_LINE_ENDINGS_CR);
  23.     esp_vfs_dev_uart_port_set_tx_line_endings(CONFIG_ESP_CONSOLE_UART_NUM, ESP_LINE_ENDINGS_CRLF);
  24.     nvs_flash_init();
  25.     wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
  26.     ESP_ERROR_CHECK(esp_wifi_init(&cfg));
  27.     wifi_config_t wifi_config = {
  28.         .sta = {
  29.             .ssid = EXAMPLE_ESP_WIFI_SSID,
  30.             .password = EXAMPLE_ESP_WIFI_PASS,
  31.             .threshold.authmode = WIFI_AUTH_WPA2_PSK,
  32.             .pmf_cfg = {
  33.                 .capable = true,
  34.                 .required = false,
  35.             },
  36.         },
  37.     };
  38.     ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA));
  39.     ESP_ERROR_CHECK(esp_wifi_set_config(WIFI_IF_STA, &wifi_config));
  40.     ESP_ERROR_CHECK(esp_wifi_start());
  41.     esp_wifi_connect();
  42.     printf("Connected...");
  43.  
  44.     char chr[40];
  45.     while(1){
  46.         printf("Enter Data : ");
  47.         scanf("%39s\n", chr);
  48.         printf(strcat(dest, chr));
  49.         esp_http_client_config_t config = {
  50.             .url = strcat(dest, chr)
  51.         };
  52.         esp_http_client_handle_t client = esp_http_client_init(&config);
  53.         esp_http_client_perform(client);
  54.         esp_http_client_cleanup(client);
  55.     }
  56. }
  57.  
I got this error :
  1. assertion "Invalid mbox" failed: file "C:/Users/XXXX/Desktop/esp-idf/components/lwip/lwip/src/api/tcpip.c", line 455, function: tcpip_send_msg_wait_sem
I have no idea how to solve this problem.

Thanks you in advance.

AH.

User avatar
mbratch
Posts: 303
Joined: Fri Jun 11, 2021 1:51 pm

Re: https request failed

Postby mbratch » Tue Sep 07, 2021 10:43 am

Why are you concatenating `chr` to `dest` twice?

Code: Select all

        printf(strcat(dest, chr));   // <-- here
        esp_http_client_config_t config = {
            .url = strcat(dest, chr)   // <-- here
        };
It's also not a good idea to concatenate to a literal string. Rather, you should do something like this:

Code: Select all

const char *pref = "https://XXXXXXXXXXXXXXXXX.com/connect.php?texte=";
char dest[100];
... // code that defines chr
strcpy(dest, pref);
strcat(dest, chr);    // <-- NOTE do this only once

axel_hpplt
Posts: 7
Joined: Thu Aug 26, 2021 8:57 pm

Re: https request failed

Postby axel_hpplt » Tue Sep 07, 2021 9:57 pm

mbratch wrote:
Tue Sep 07, 2021 10:43 am
Why are you concatenating `chr` to `dest` twice?

Code: Select all

        printf(strcat(dest, chr));   // <-- here
        esp_http_client_config_t config = {
            .url = strcat(dest, chr)   // <-- here
        };
It's also not a good idea to concatenate to a literal string. Rather, you should do something like this:

Code: Select all

const char *pref = "https://XXXXXXXXXXXXXXXXX.com/connect.php?texte=";
char dest[100];
... // code that defines chr
strcpy(dest, pref);
strcat(dest, chr);    // <-- NOTE do this only once
Thanks you for your reply. So, I've made your changes :
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include "esp_system.h"
  4. #include "esp_console.h"
  5. #include "esp_vfs_dev.h"
  6. #include "esp_vfs_fat.h"
  7. #include "esp_wifi.h"
  8. #include "driver/uart.h"
  9. #include "nvs_flash.h"
  10. #include "esp_http_client.h"
  11.  
  12. #define EXAMPLE_ESP_WIFI_SSID "iPhone de Axel"
  13. #define EXAMPLE_ESP_WIFI_PASS "axelcroque2002"
  14.  
  15. void app_main(void)
  16. {  
  17.     const char *pref = "https://101testingesp32.000webhostapp.com/connect.php?texte=";
  18.     char dest[100];
  19.     setvbuf(stdin, NULL, _IONBF, 0);
  20.     setvbuf(stdout, NULL, _IONBF, 0);
  21.     ESP_ERROR_CHECK(uart_driver_install(CONFIG_ESP_CONSOLE_UART_NUM, 256, 0, 0, NULL, 0));
  22.     esp_vfs_dev_uart_use_driver(CONFIG_ESP_CONSOLE_UART_NUM);
  23.     esp_vfs_dev_uart_port_set_rx_line_endings(CONFIG_ESP_CONSOLE_UART_NUM, ESP_LINE_ENDINGS_CR);
  24.     esp_vfs_dev_uart_port_set_tx_line_endings(CONFIG_ESP_CONSOLE_UART_NUM, ESP_LINE_ENDINGS_CRLF);
  25.     nvs_flash_init();
  26.     wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
  27.     ESP_ERROR_CHECK(esp_wifi_init(&cfg));
  28.     wifi_config_t wifi_config = {
  29.         .sta = {
  30.             .ssid = EXAMPLE_ESP_WIFI_SSID,
  31.             .password = EXAMPLE_ESP_WIFI_PASS,
  32.             .threshold.authmode = WIFI_AUTH_WPA2_PSK,
  33.             .pmf_cfg = {
  34.                 .capable = true,
  35.                 .required = false,
  36.             },
  37.         },
  38.     };
  39.     ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA));
  40.     ESP_ERROR_CHECK(esp_wifi_set_config(WIFI_IF_STA, &wifi_config));
  41.     ESP_ERROR_CHECK(esp_wifi_start());
  42.     esp_wifi_connect();
  43.     printf("Connected...");
  44.  
  45.     char chr[40];
  46.     while(1){
  47.         printf("Enter Data : ");
  48.         scanf("%39s\n", chr);
  49.         strcpy(dest, pref);
  50.         esp_http_client_config_t config = {
  51.             .url = strcat(dest, chr)
  52.         };
  53.         esp_http_client_handle_t client = esp_http_client_init(&config);
  54.         esp_http_client_perform(client);
  55.         esp_http_client_cleanup(client);
  56.     }
  57. }
But, I get the same error. Does anyone else have a solution please ?

ESP_Sprite
Posts: 9765
Joined: Thu Nov 26, 2015 4:08 am

Re: https request failed

Postby ESP_Sprite » Wed Sep 08, 2021 2:28 am

Note that esp_wifi_connect() only *starts* a connection attempt, and will return more-or-loss immediately; the connection isn't actually created at that time. Suggest you check e.g. the examples in esp-idf to see how to properly wait until it is.

axel_hpplt
Posts: 7
Joined: Thu Aug 26, 2021 8:57 pm

Re: https request failed

Postby axel_hpplt » Wed Sep 08, 2021 11:11 am

ESP_Sprite wrote:
Wed Sep 08, 2021 2:28 am
Note that esp_wifi_connect() only *starts* a connection attempt, and will return more-or-loss immediately; the connection isn't actually created at that time. Suggest you check e.g. the examples in esp-idf to see how to properly wait until it is.
Thanks for your answer, I looked at what you told me (esp-idf/examples/wifi/getting-started/station) but I didn't find the way to wait properly, could you enlighten me?

User avatar
fasani
Posts: 197
Joined: Wed Jan 30, 2019 12:00 pm
Location: Barcelona
Contact:

Re: https request failed

Postby fasani » Sat Sep 11, 2021 6:21 am

Hello Axel,
You need to use events, just as the example uses, in order to get it working.
epdiy collaborator | http://fasani.de Fan of Espressif MCUs and electronic design

ESP_YJM
Posts: 300
Joined: Fri Feb 26, 2021 10:30 am

Re: https request failed

Postby ESP_YJM » Sun Sep 26, 2021 6:20 am

Maybe you missed the esp_netif_init(), you can follow https://github.com/espressif/esp-idf/bl ... .c#L70-L73

Who is online

Users browsing this forum: Google [Bot] and 217 guests