cancel
Showing results for 
Search instead for 
Did you mean: 

Problem while sending TCP packet with STM32F746NG to Raspberry Pi (ST32CubeIDE, LWIP)

KFrei.2
Associate

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.

0693W000007BS6CQAW.png 

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

3 REPLIES 3
Tilen MAJERLE
ST Employee

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

  • implement connected callback, check response if connected and then send the packet
  • Parameter tcp_write is not pbuf buffer pointer, but actual data to write. You do not need to do any pbuf alloc since you use COPY flag
  • TCP_RAW functions shall not be called in thread, you NETCONN or SOCKET API in OS context, or protect LwIP from concurrent access.
KFrei.2
Associate

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.

Piranha
Chief II

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...

https://community.st.com/s/question/0D50X0000BOtfhnSQB/how-to-make-ethernet-and-lwip-working-on-stm32