I am trying to send an UDP broadcast with the following code:
void write_UDP(uint8_t *buffer, int length)
{
static struct espconn *myEspconn;
unsigned long remote_ip;
ip_addr_t ipaddr;
ets_uart_printf("Sending UDP data!\r\n");
myEspconn = (struct espconn *)os_malloc(sizeof(struct espconn));
myEspconn->type = ESPCONN_UDP;
myEspconn->state = ESPCONN_NONE;
myEspconn->proto.udp = (esp_udp *)os_malloc(sizeof(esp_udp));
myEspconn->proto.udp->local_port = UDP_BROADCAST_PORT;
myEspconn->proto.udp->remote_port = UDP_BROADCAST_PORT;
remote_ip = IPADDR_NONE;
IP4_ADDR(&ipaddr, 255, 255, 255, 255);
os_memcpy(myEspconn->proto.udp->remote_ip, &ipaddr.addr, 4);
ets_uart_printf("ip addres: %x\r\n", ipaddr.addr);
ets_uart_printf("ip addres: " IPSTR "\r\n", IP2STR(&ipaddr.addr));
if (!espconn_send(myEspconn, buffer, length))
ets_uart_printf("espconn_send error!\r\n");
else
ets_uart_printf("espconn_send succeeded!\r\n");
}Could anybody please help me to find out what is wrong here?
Thank you and best regards,
Wamor