RT1064 freertos lwip udp example receive from broadcast

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

RT1064 freertos lwip udp example receive from broadcast

1,889 Views
akift
Contributor I

Hi,

I am working on RT1064EVK and using I evkmimxrt1064_lwip_ipv4_ipv6_echo_freertos example.

udp echo example receives the data which send to device IP only.

But I would like to receive the broadcast data - which send to any IP-  and specific port.

What modifications I need to do in the example code?

 

I may need to add below lwipopts.h.

#define IP_SOF_BROADCAST 1
#define IP_SOF_BROADCAST_RECV 1
#define LWIP_BROADCAST_PING 1

And after I need to change binding address to IP_ADDR_ANY.
But I couldn't find where to change.

Any help would be appreciated. Thanks

Labels (1)
0 Kudos
Reply
5 Replies

1,730 Views
jaylarson
Contributor II

Hi @akift,

I'm not sure @kerryzhou understood your question. 

I have managed to receive broadcasts using code like the following snippet:

	struct netconn *pListenerConnection = netconn_new(NETCONN_UDP);
	if (!pListenerConnection)
	{
		// failed to listen
		DebugPrintf("listener failed on netconn_new()\n");
		goto restart;
	}

	struct netbuf *pBuf;
	lastNetError = netconn_bind(pListenerConnection, IP_ADDR_ANY, listenPort);
	if (ERR_OK != lastNetError)
	{
		// failed to listen
		DebugPrintf("Listener failed on netconn_bind(), return %i\n", lastNetError);
		netconn_delete(pListenerConnection);
		goto restart;
	}

	// process requests from possible clients.
	while (1)
	{
		lastNetError = netconn_recv(pListenerConnection, &pBuf);

		// depending on the return
		if (ERR_OK != lastNetError)
		{
			// some error.
			DebugPrintf("listener got error %i in netconn_recv()\n", lastNetError);
			// restart the connection
			netconn_delete(pListenerConnection);
			goto restart;
		};
		// pBuf has the message:  
		uint8_t packet[8];  // just interested in the first this many bytes
		size_t packetSize = netbuf_copy(pBuf, packet, sizeof(packet));

		if (packetSize != sizeof(packet))
		{
			DebugPrintf("listener got an unexpected request, not %d bytes long.\n", packetSize);
			// delete the pBuf and wait for another UDP packet.
			netbuf_delete(pBuf);
			continue;
		}
      // use the data in packet.

		netbuf_delete(pBuf);
	}


 I hope it helps.

 

Cheers,

1,844 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi @akift ,

  This post also useful to you:

https://blog.csdn.net/m0_61659911/article/details/132415649

 

Wish it helps you!

Best Regards,

Kerry

0 Kudos
Reply

1,845 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi @akift ,

  Thanks for your interest in the NXP MIMXRT product, I would like to provide service for you.

  I don't have the broadcast demo, but I write a multicast demo previously.

  I think, you also can refer to my multicast doc, I also share one document, but just write in Chinese, the doc contains the code and test result picture.

  If you still have question about it, please kindly let me know.

Best Regards,

Kerry

0 Kudos
Reply

1,836 Views
akift
Contributor I

Hi @kerryzhou,

Thank you but your reply is not helpful. Also the implementations are very different than NXP example.

When I scrutinize the information in the two examples, I can only conclude that LWIP_IGMP is not defined.

I have defined #define LWIP_IGMP 1 in lwipopts.h , but still I can't receive broadcast data.

Could you have a look evkmimxrt1064_lwip_ipv4_ipv6_echo_freertos example in the SDK?

The example is provided by NXP, so I assume you or your colleagues  can help us very easily. Probably a small change is needed to receive broadcast data over udp. 
I have tried the change mentioned in the first post but it is not working. There might be a bug in the example.

Thanks

0 Kudos
Reply

1,768 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi @akift ,

  My example is the multicast, not the broadcast.

 To the broadcast, do you try this code:

kerryzhou_0-1711939401955.png

 

You can try it again.

 

Wish it helps you!

If you still have question about it, please kindly let me know.

Best Regards,

Kerry

 

   

0 Kudos
Reply