[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [lwip-users] Multicast on lwip

From: Noam weissman
Subject: Re: [lwip-users] Multicast on lwip
Date: Thu, 24 Apr 2014 09:14:30 +0300



Either you made a typo or you do things in the wrong order.


You wrote “Join multicast group, create and bind pcb;”


You cannot join an IGMP group before you have a network live and connected. That means

you first need to bind…



This is the code I use. I omitted private code and left only the function code that concerns you:


void IntiFunction(void)


  struct udp_pcb *pcb;

  err_t err;

  struct ip_addr JoinToGroup, OwnAddress;

  int Retry;



#ifndef LWIP_IGMP

  #error "LWIP_IGMP not defined, add it in lwipopts.h file !!!!"




   // create a new pcb for the server. This is not the pcb used for the connection.

   pcb = udp_new();


   if(pcb != NULL)


     // bind the listening port to our own IP. Actually opening

     // the socket for listening.

     err = udp_bind(pcb, IP_ADDR_ANY, LISTENING_PORT);


     // if binding was OK try to join our own multicast group as well

     // and initialize the rest of the code.

     if(err == ERR_OK)


       // send out a join group request:

       JoinToGroup.addr = IP_MCAST_GROUP;

       OwnAddress.addr = IP_ANY_ADDR;



       while((Retry--) > 0)


         err = igmp_joingroup(&OwnAddress, &JoinToGroup);


         if(err == ERR_OK)





         vTaskDelay(IGMP_JOIN_RETRY_DELAY / portTICK_RATE_MS);




       if(err != ERR_OK)


         // error could not join group. We only can listen to broadcast messages.




       // hook the recv function to the new pcb      

       udp_recv(pcb, recv_func, pcb);




       // do something here ??





     // abort? output diagnostic?  






*** Important note:

When you first load your system network connection to the router or gateway may take some time. If you try

to join the MC group before the connection is alive the call to igmp_joingroup will fail although it looks like your

stack is running OK.


Let me explain. In the code I use which is based on an example, the main application creates a temporary

task that initializes LwIP and then dies. Part of the initialization process is creating the LwIP own task.


Every task has its own priority.


As the temporary task needs to run before LwIP own task its priority is higher  !

If the temporary task priority is higher than the LwIP own task priority this causes a problem. If you join

the MC group as part of this initialization process igmp_joingroup will fail as the LwIP is not yet running.


To overcome this I have done the following:

TCP initialization task priority is higher than LwIP own task, let’s say 10

LwIP own task priority is 9


I added a long task delay in the temporary task after calling tcpip_init function


The above causes the temporary task to halt, LwIP finishes its own initialization.


The OS scheduler will resume the temporary task and now if you call igmp_joingroup it will not fail.


See the code here:



If the above temporary looks something like this:


void vStartEthernetTasks( void* param )


  // this function should be called after calling NVIC, GPIO and RCC settings.


  // This function was originally in main but for some reason ETH was not running

  // in stand alone mode. If code was loaded from the debugger and run it was working.

  // After moving it here it started to work





  // read IP address, port and other definitions from Flash 




  // initialize the network netif structure before calling ethernetif_init.

  // once TCP stack has been initalized, set hw and IP parameters, initialize MAC too.

  tcpip_init(prvEthernetConfigureInterface, NULL);



  // the function prvEthernetConfigureInterface must be called before we continue

  // with the initializtion of the rest of the moduls. TCP stack has higher priority

  // than vStartEthernetTasks so yeilding here lets it run first !!!




  // Initialize HTTP




  // Nothing else to do.  No point hanging around.

  vTaskDelete( NULL );






I hope that helped J









From: address@hidden [mailto:address@hidden On Behalf Of ryan.jin
Sent: Wednesday, April 23, 2014 1:42 PM
To: lwip-users
Subject: [lwip-users] Multicast on lwip


Hi all,


I'm new to lwip, and I want to create a multicast receiver with lwip. My steps are as follow:

1. Enable LWIP_IGMP;

2. Set NETIF_FLAG_IGMP in low_level_init();

3. Join multicast group, create and bind pcb;

4. udp_connect to remote_ip (or multicast IP address? Both are tried but failed)


Joining group returns success, and everything looks fine when program executing this. However the multicast doesn't work. Does any one know what I'm missing? 


I found "netif->igmp_mac_filter != NULL" in igmp_joingroup(), but it is set as NULL and not implemented. Do I need to implement it by myself to set the filter or it is OK just leave it as NULL?

Thanks a lot for your help!

Best regards,

Ryan Jin

This footnote confirms that this email message has been scanned by
PineApp Mail-SeCure for the presence of malicious code, vandals & computer viruses.

This footnote confirms that this email message has been scanned by
PineApp Mail-SeCure for the presence of malicious code, vandals & computer viruses.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]