2021-01-15 05:58 AM
Hello everyone,
What i am trying:
I am trying to send a http Request (with a TCP connection and LwIp) with my STM32F746NG controller to my Respberry PI. The Webserver on that Raspberry Pi has a RestApi. So I can send a command with the http request. I don't want to receive anything.
I am using the ST32CubeIDE, Ethernet, LWIP, freeRTOS.
How I do it:
I configured a thread to establish a TCP connection and to send my defined http Request.
void StartTestTask(void const * argument)
{
/* USER CODE BEGIN StartTestTask */
struct netconn *xNetConn = NULL;
struct netbuf *Buf = NULL;
ip_addr_t local_ip, remote_ip;
u16_t m_len;
IP_ADDR4(&remote_ip, 192, 168, 1, 20);
IP_ADDR4(&local_ip, 192, 168, 1, 220);
//char* message = "GET /fhem?cmd=set+mx_lamp+toggle HTTP/1.1\r\nHost:192.168.1.20:8088\r\n\r\n";
char *message = "test";
m_len = strlen( message );
xNetConn = netconn_new ( NETCONN_TCP );
netconn_bind ( xNetConn, &local_ip, 80 );
netconn_connect ( xNetConn, &remote_ip, 8088 );
osDelay(1000);
Buf = netbuf_new();
netbuf_alloc(Buf, 10); // 4 bytes of buffer
Buf->p->payload = message;
Buf->p->len = m_len;
netconn_write(xNetConn, Buf->p->payload, Buf->p->len, NETCONN_COPY );
vTaskDelay(100); // To see the result easily in Comm Operator
netbuf_delete(Buf);
/* Infinite loop */
for (;;) {
}
/* USER CODE END StartTestTask */
}
The Problem:
On my Raspberry Pi, I can see with Wireshark, that the TCP connection is working and the package is sent to the right IP adress and Port. But the data of the package looks very strange and the web server is doing nothing.
So I think the http request is not written correctly to the TCP package.
I googled a lot but can't find any solution. Hope someone can help me.
Thank you in advance to everyone
2021-01-15 06:12 AM
tcp_connect function does not return after you are connected, but it sends packet and returns immediately. It is a non-blocking function, and your "NULL" parameter in the function is actually "connected" callback where you continue to send your buffer.
https://www.nongnu.org/lwip/2_0_x/group__tcp__raw.html#ga9a31deea4cadacd39f9485f37cfdd012
2021-01-15 08:53 AM
Hey, thanks for your reply. I changed the code (updated in question). Because i am using FreeRTOS i know use the NETCONN API.
But i have the same problem with NETCONN API, i can't see my sent data with wireshark.
2021-01-16 03:10 AM
You don't need a buffer allocation to send a simple message.
const char message[] = "test";
netconn_write(xNetConn, message, sizeof(message) - 1, NETCONN_COPY);
And ST doesn't provide a working network stack...