TCP Socket API over ethernet for imxrt1176

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

TCP Socket API over ethernet for imxrt1176

跳至解决方案
4,133 次查看
Devaharsha
Contributor III

Hi @kerryzhou,

Continuation to this thread: https://community.nxp.com/t5/i-MX-Processors/Using-Socket-API-in-imxrt1176/m-p/1681959#M208699

 

Sorry for late reply.

Thanks for the files. I have written the client socket code as you mentioned in the attached file. And I am running a server on my laptop written using python. Everything is working fine. 

The issue I am facing is:

 1) When I am trying to receive data over socket, its not receiving correctly. Like if I am sending "Hello", its receiving as "Hell" or "llo", etc. Though its receiving correctly also sometimes. 

Correct me if I am wrong, I suspect a problem is in:

1) Send socket is done using server which is executing send function in an infinite for loop without delay.

2) Recv function is executing on imxrt1176 with 1ms task delay.

3) Is the issue related to timing? 

and also if I want to set socket in non-blocking state, I can't see any non-blocking option under setsockopt() function. But in send and recv function, under flags parameters it can be given. Is it correct or I am missing something?

0 项奖励
回复
1 解答
4,047 次查看
kerryzhou
NXP TechSupport
NXP TechSupport

Hi @Devaharsha ,

  Good news to you, I write a socket client project and document, which can resolved your mentioned issues:

https://community.nxp.com/t5/i-MX-RT-Knowledge-Base/RT1170-LWIP-socket-client-demo/ta-p/1690055

 

Wish it helps you!

Best Regards,

kerry

在原帖中查看解决方案

0 项奖励
回复
6 回复数
4,048 次查看
kerryzhou
NXP TechSupport
NXP TechSupport

Hi @Devaharsha ,

  Good news to you, I write a socket client project and document, which can resolved your mentioned issues:

https://community.nxp.com/t5/i-MX-RT-Knowledge-Base/RT1170-LWIP-socket-client-demo/ta-p/1690055

 

Wish it helps you!

Best Regards,

kerry

0 项奖励
回复
4,035 次查看
Devaharsha
Contributor III

Thank you. The code is modified as you have sent before and it's working totally fine, even with delay of 1ms.

0 项奖励
回复
4,028 次查看
kerryzhou
NXP TechSupport
NXP TechSupport

Hi @Devaharsha ,

   Cool! Thanks for your positive feedback, that also gives me more confidence to write more documents with my own experience in the community.

   If you meet any issues in the future, welcome to create the new questions post, thanks.

 

Best Regards,

Kerry

 

0 项奖励
回复
4,112 次查看
kerryzhou
NXP TechSupport
NXP TechSupport

Hi @Devaharsha ,

   Thanks for your cooperation for the new question post.

  Now, your test platform is NXP MIMXT1170-EVK? Or EVKB, please let me know your board.

  Please also attach your modified socket project for the RT1170, I will find time to test it, I will also use the 3rd part tool to transfer the data to the board socket recevie, in the previous time which I am testing the RT1060, I didn't meet the receive issues.

  So, for the RT1170 socket, I also need to find time to test it.

  You also can share your python testing tool to me for testing.

Best Regards,

Kerry

0 项奖励
回复
4,106 次查看
Devaharsha
Contributor III

Hi,

I am using iMXRT1176 (imxrt 1170 EVK board). I have attached the socket function modified and also the python server code. Please find the attachment.

 

Thanks

Devaharsha

0 项奖励
回复
4,101 次查看
kerryzhou
NXP TechSupport
NXP TechSupport

Hi @Devaharsha ,

  So sorry for my later reply.

  Talk about your issues.

  You already can receive the data, and just can't receive it complete, it means your socket already works, I think it is related to the time, you mentioned task is 1ms delay, I think it is not enough, please use long time, eg, 1s, then test it again.

In the previous time, I have even test the socket to receive a lot of data, it also works, you can check my post:

https://community.nxp.com/t5/i-MX-RT-Knowledge-Base/The-RT-speech-recognition-system-based-on-VIT-to...

The related function is:

static void
weather_thread(void *arg)
{
	  int sock = -1,rece;
	  struct sockaddr_in client_addr;

	  char* host_ip;
	  ip4_addr_t dns_ip;
	  err_t err;

	  uint32_t *pSDRAM= pvPortMalloc(BUF_LEN);//
//==============
//DNS resolving have issues
#if 0
	    if (ipaddr_aton(HOST_NAME, &dns_ip) && IP_IS_V4(&dns_ip))
	    {
	        /* Already an IP address */
	        err = ERR_OK;
	    }
	    else
	    {
	        /* Resolve MQTT broker's host name to an IP address */
	        PRINTF("Resolving \"%s\"...\r\n", HOST_NAME);
	        err = netconn_gethostbyname(HOST_NAME, &dns_ip);
	    }
	    PRINTF("host name : %s , host_ip : %s\r\n",HOST_NAME,host_ip);
#endif
//===================
	#ifdef  LWIP_DNS
	    ip4_addr_t dns_ip;
	    netconn_gethostbyname(HOST_NAME, &dns_ip);
	    host_ip = ip_ntoa(&dns_ip); //DSN get IP
	    // host_ip = IP_ADDR;
	    PRINTF("host name : %s , host_ip : %s\r\n",HOST_NAME,host_ip);
	#else
	    host_ip = HOST_NAME;
	    PRINTF("host name : %s , host_ip : %s\r\n",HOST_NAME,host_ip);
	#endif

	  while(1)
	  {
	  //add the command request, only cmd == weather flag, then call it.
        if((weather_data.ww_flag ==  1))
        {
    	 if(weather_data.vc_index >= 3)
    	 {

		   // create connection
	       sock = socket(AF_INET, SOCK_STREAM, 0);
	       if (sock < 0)
	       {
	         PRINTF("Socket error\n");
	         vTaskDelay(10);
	         continue;
	        }
	       client_addr.sin_family = AF_INET;
	       client_addr.sin_port = htons(PORT);
	       client_addr.sin_addr.s_addr = inet_addr(host_ip);
	       memset(&(client_addr.sin_zero), 0, sizeof(client_addr.sin_zero));


	       if (connect(sock, (struct sockaddr *)&client_addr,  sizeof(struct sockaddr)) == -1)
	       {
	          PRINTF("Connect failed!\n");
	          closesocket(sock);
	          vTaskDelay(10);
	          continue;
	       }

	       PRINTF("Connect to server successful!\r\n");

	       //  PRINTF("\r\n************************************************************\n\r");
	       //  PRINTF("\r\n Begin write\n\r");
	       write(sock,get_weather,sizeof(get_weather));
	       while (1)
	       {
		      //receive data
	          rece = recv(sock, (uint8_t*)pSDRAM, BUF_LEN, 0);//BUF_LEN
	          if (rece <= 0)
	            break;

	           //  PRINTF("%s\n",(uint8_t*)pSDRAM);
               memcpy(weather_data.weather_info, pSDRAM,1500);//max 1457
	           //   PRINTF("---rece=%d\n",rece);
	           //   PRINTF("\r\n*******************receive data*******************************\n\r");

	       }
	      //   PRINTF("\r\n***************************end*******************************\n\r");

	       //weather process
	       Weather_process();

	       memset(pSDRAM,0,BUF_LEN);
	       closesocket(sock);
    	 }
         //clean data
	     memset(weather_data.weather_info, 0, sizeof(weather_data.weather_info));
 	     weather_data.ww_flag = 0;
 	     weather_data.vc_index = 0;
        }

	    vTaskDelay(10000);//about 10s //10000
	  }


}

You can see, I even use 10s, as my data is large.

I also test the RT1170 socket on my side, but seems recently, our IT limit the ENET cable, so my office PC even connection have issues, but I am sure my code is the correct one, as I have tested previously when the PC have no enet limit.

So, you can refer to my above code, use long delay, and try it again.

Wish it helps you!
Best Regards,

Kerry

0 项奖励
回复