Open AndyW999 opened 12 months ago
I did post to Github https://github.com/espressif/arduino-esp32/issues/8397 But did not get any response so this works -
IPAddress remote_ip {0, 0, 0, 0}; // IP address of the local WG interface IPAddress local_ip {0, 0, 0, 0}; // IP address of the remote WG interface uint8_t rx_buffer[1600]; // received data
void udp_rtp_init(uint16_t port) { err_t err;
/ Create a new UDP control block / upcb_rtp = udp_new(); ip_set_option(upcb_rtp, SOF_BROADCAST);
if(upcb_rtp) { udp_rtp_port = port; if(upcb_rtp) { udp_rtp_port = port; / Bind the upcb to the UDP_PORT port / IP4_ADDR( &udp_rtp_addr.u_addr.ip4, remote_ip[0], remote_ip[1], remote_ip[2], remote_ip[3]); IP4_ADDR( &wg_local_addr.u_addr.ip4, local_ip[0], local_ip[1],local_ip[2], local_ip[3]); err = udp_bind(upcb_rtp, &wg_local_addr, port);
if(err == ERR_OK)
{
/* Set a receive callback for the upcb */
udp_recv(upcb_rtp, udp_rtp_receive_callback, NULL);
}
else
{
printf("can not bind pcb");
}
upcb_rtp->remote_port = udp_rtp_port;
} else { printf("can not create pcb"); } }
void udp_rtp_receive_callback(void arg, struct udp_pcb upcb, struct pbuf p, const ip_addr_t addr, short unsigned int port) { uint16_t i, j;
j = p->len; memcpy(rx_buffer, p->payload, p->len);
return; }
void udp_rtp_tx(unsigned char data, unsigned short int len) { if(udp_ready == true) { if (upcb_rtp->remote_port != (uint16_t)0) { struct pbuf p = pbuf_alloc(PBUF_TRANSPORT, len, PBUF_RAM); memcpy(p->payload, data, len); udp_sendto(upcb_rtp, p, &udp_rtp_addr, udp_rtp_port); pbuf_free(p); } } }
When using with PlatformIO and receiving a Wireguard packet there is a Guru Meditation Error.
If WiFiUdp is used it works OK but packets cannot be processed fast enough this is why I want to use AsyncUDP .
AsyncUDP works OK without Wireguard.
I suspect that the Wireguard netif is not being found.
Please see attached files.
Thanks
Andy.
main.zip