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 :

Code: Untitled.c Select all


#include <stdio.h>
#include <string.h>
#include "esp_system.h"
#include "esp_console.h"
#include "esp_vfs_dev.h"
#include "esp_vfs_fat.h"
#include "esp_wifi.h"
#include "driver/uart.h"
#include "nvs_flash.h"
#include "esp_http_client.h"

#define EXAMPLE_ESP_WIFI_SSID "iPhone"
#define EXAMPLE_ESP_WIFI_PASS "XXXXXXXXXXXX"

void app_main(void)
{
char dest[100] = "https://XXXXXXXXXXXXXXXXX.com/connect.php?texte=";
setvbuf(stdin, NULL, _IONBF, 0);
setvbuf(stdout, NULL, _IONBF, 0);
ESP_ERROR_CHECK(uart_driver_install(CONFIG_ESP_CONSOLE_UART_NUM, 256, 0, 0, NULL, 0));
esp_vfs_dev_uart_use_driver(CONFIG_ESP_CONSOLE_UART_NUM);
esp_vfs_dev_uart_port_set_rx_line_endings(CONFIG_ESP_CONSOLE_UART_NUM, ESP_LINE_ENDINGS_CR);
esp_vfs_dev_uart_port_set_tx_line_endings(CONFIG_ESP_CONSOLE_UART_NUM, ESP_LINE_ENDINGS_CRLF);
nvs_flash_init();
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
ESP_ERROR_CHECK(esp_wifi_init(&cfg));
wifi_config_t wifi_config = {
.sta = {
.ssid = EXAMPLE_ESP_WIFI_SSID,
.password = EXAMPLE_ESP_WIFI_PASS,
.threshold.authmode = WIFI_AUTH_WPA2_PSK,
.pmf_cfg = {
.capable = true,
.required = false,
},
},
};
ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA));
ESP_ERROR_CHECK(esp_wifi_set_config(WIFI_IF_STA, &wifi_config));
ESP_ERROR_CHECK(esp_wifi_start());
esp_wifi_connect();
printf("Connected...");

char chr[40];
while(1){
printf("Enter Data : ");
scanf("%39s\n", chr);
printf(strcat(dest, chr));
esp_http_client_config_t config = {
.url = strcat(dest, chr)
};
esp_http_client_handle_t client = esp_http_client_init(&config);
esp_http_client_perform(client);
esp_http_client_cleanup(client);
}
}
I got this error :

Code: Untitled.txt Select all

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

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 :

Code: Untitled.c Select all

#include <stdio.h>
#include <string.h>
#include "esp_system.h"
#include "esp_console.h"
#include "esp_vfs_dev.h"
#include "esp_vfs_fat.h"
#include "esp_wifi.h"
#include "driver/uart.h"
#include "nvs_flash.h"
#include "esp_http_client.h"

#define EXAMPLE_ESP_WIFI_SSID "iPhone de Axel"
#define EXAMPLE_ESP_WIFI_PASS "axelcroque2002"

void app_main(void)
{
const char *pref = "https://101testingesp32.000webhostapp.com/connect.php?texte=";
char dest[100];
setvbuf(stdin, NULL, _IONBF, 0);
setvbuf(stdout, NULL, _IONBF, 0);
ESP_ERROR_CHECK(uart_driver_install(CONFIG_ESP_CONSOLE_UART_NUM, 256, 0, 0, NULL, 0));
esp_vfs_dev_uart_use_driver(CONFIG_ESP_CONSOLE_UART_NUM);
esp_vfs_dev_uart_port_set_rx_line_endings(CONFIG_ESP_CONSOLE_UART_NUM, ESP_LINE_ENDINGS_CR);
esp_vfs_dev_uart_port_set_tx_line_endings(CONFIG_ESP_CONSOLE_UART_NUM, ESP_LINE_ENDINGS_CRLF);
nvs_flash_init();
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
ESP_ERROR_CHECK(esp_wifi_init(&cfg));
wifi_config_t wifi_config = {
.sta = {
.ssid = EXAMPLE_ESP_WIFI_SSID,
.password = EXAMPLE_ESP_WIFI_PASS,
.threshold.authmode = WIFI_AUTH_WPA2_PSK,
.pmf_cfg = {
.capable = true,
.required = false,
},
},
};
ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA));
ESP_ERROR_CHECK(esp_wifi_set_config(WIFI_IF_STA, &wifi_config));
ESP_ERROR_CHECK(esp_wifi_start());
esp_wifi_connect();
printf("Connected...");

char chr[40];
while(1){
printf("Enter Data : ");
scanf("%39s\n", chr);
strcpy(dest, pref);
esp_http_client_config_t config = {
.url = strcat(dest, chr)
};
esp_http_client_handle_t client = esp_http_client_init(&config);
esp_http_client_perform(client);
esp_http_client_cleanup(client);
}
}
But, I get the same error. Does anyone else have a solution please ?

Sprite
Espressif staff
Espressif staff
Posts: 10599
Joined: Thu Nov 26, 2015 4:08 am

Re: https request failed

Postby 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

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

YJM
Espressif staff
Espressif staff
Posts: 304
Joined: Fri Feb 26, 2021 10:30 am

Re: https request failed

Postby 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: meta-externalagent and 5 guests