cancel
Showing results for 
Search instead for 
Did you mean: 

How receive UDP Broadcast with LwIP ?

Peko
Associate III

Hello,

I have this problem. I need to receive UDP Broadcast, but The "callback" function is never called.

I use LwIP 2.0.3.

/*----- Default Value for IP_SOF_BROADCAST: 0 ---*/
#define IP_SOF_BROADCAST 1
/*----- Default Value for IP_SOF_BROADCAST_RECV: 0 ---*/
#define IP_SOF_BROADCAST_RECV 1
   
void udp_server_init(void)
{
     struct udp_pcb *upcb;
     err_t err;
       
     upcb = udp_new();
     ip_set_option(upcb, SOF_BROADCAST);
    
     if (upcb)
     {
         err = udp_bind(upcb, IP_ADDR_BROADCAST, 8000);
        
         if(err == ERR_OK)
         {
            udp_recv(upcb, udp_receive_callback, NULL);
         }
     }
}
 
void udp_receive_callback(void *arg, struct udp_pcb *upcb, struct pbuf *p, const ip_addr_t *addr, u16_t port)
{
   HAL_GPIO_TogglePin(GPIOE, GPIO_PIN_2);
    	
   pbuf_free(p);		// Free the p buffer
    
   //udp_transmit(upcb, addr, udp2_tx_data, udp2_tx_len);
}  

What is wrong ?

Peter

0 REPLIES 0