energia / Energia

Fork of Arduino for the Texas Instruments LaunchPad's
http://energia.nu
Other
798 stars 670 forks source link

How to implement UDP Multicast with EthernetUDP.h #927

Open ccastillop opened 8 years ago

ccastillop commented 8 years ago

I wonder if it is possible to implement UDP Multicast over Ethernet UDP.h library with TM4c1294 I have not find any doc neither example related If there is any example of that implementation I will appreciate it Thanks

Thinkulator commented 7 years ago

I was able to get UDP Multicast working for UPNP recently, it was not a ton of work, but required a few modifications to some non-project files that I still need to clean up.

Here's the details for now: in your .energia directory (where the compiler and libraries are stored): packages/energia/hardware/tivac/1.0.2/libraries/Ethernet/lwip/opt.h

packages/energia/hardware/tivac/1.0.2/libraries/Ethernet/utility/tiva-tm4c129.c Add function for random number generator long lw_random_num(){ return 0xDEADBEEF; //I cheated to get it working, I have not come back to fix it yet. }

This gets the core of IGMP multicast working - now we can join multicast groups in our code

include "lwip/igmp.h"

ip_addr_t ipaddr; ip_addr_t ipgroup;

//Join the multicast groups used for UPNP device discovery ip_addr_set_any(&ipaddr); //multicast listen on all ip addresses IP4_ADDR(&ipgroup,239,255,255,250); Serial.println(igmp_joingroup( &ipaddr, &ipgroup )); IP4_ADDR(&ipgroup,239,11,3,8); Serial.println(igmp_joingroup( &ipaddr, &ipgroup ));

Both of the printlns should output 0 (success).

With this in place, any UDP listener will pick up UDP multicast packets - and I was able to successfully emulate a belkin Wemo device using the TM4c1294.

If there is interest, and IGMP can be enabled by default (or configurably) - I would be willing to turn this into a proper library.