Skip to content

Instantly share code, notes, and snippets.

@malachib
Created December 21, 2016 12:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save malachib/151e3702d38d96e6683e2eded8f021d8 to your computer and use it in GitHub Desktop.
Save malachib/151e3702d38d96e6683e2eded8f021d8 to your computer and use it in GitHub Desktop.
igmp_joingroup code... fails with a -6
bool UDP_Multicast_init(void)
{
//bool IGMP_joined;
struct ip_addr ipgroup;
struct udp_pcb *g_udppcb;
char msg[] = "gaurav";
struct pbuf* p;
p = pbuf_alloc(PBUF_TRANSPORT,sizeof(msg),PBUF_RAM);
memcpy (p->payload, msg, sizeof(msg));
struct ip_info local_ip;
const uint8_t mode = sdk_wifi_get_opmode();
if (mode & STATION_MODE) {
sdk_wifi_get_ip_info(STATION_IF, &local_ip);
} else {
sdk_wifi_get_ip_info(SOFTAP_IF, &local_ip);
}
//224.0.1.186
//IP4_ADDR(&ipgroup, 238, 0, 0, 3 ); //MultiCasting Ipaddress.
IP4_ADDR(&ipgroup, 224, 0, 1, 186 ); //MultiCasting Ipaddress.
g_udppcb =( struct udp_pcb*) udp_new();
udp_bind(g_udppcb, IP_ADDR_ANY, 5683); //to receive multicast
udp_recv(g_udppcb, NET_UDP_rec,NULL);// (void *)0); //NET_UDP_rec is the callback function that will be called every time you receive multicast
#if LWIP_IGMP
int iret = igmp_joingroup(&local_ip.ip,(struct ip_addr *)(&ipgroup));
printf("ret of igmp_joingroup: %d \n\r",iret);
#endif
udp_sendto(g_udppcb,p,&ipgroup,5683); //send a multicast packet
return iret == 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment