Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
7 years, 9 months ago.
UDP not working on K64F?
Hi,
Im using the FRDM-K64F with mbed OS 5, and am trying to broadcast a UDP message. The Ethernet connects to DHCP fine and TCP connections work fine, but UDP doesnt seem to. It returns -3003 (NSAPI_ERROR_PARAMETER), and wireshark confirms no packets went out.
I believe im setting up the socket correctly, but I suspect the issue is in my sendto() method usage, where data is of type 'const void *data'. Im using a char array as i've never seen a 'const void pointer' in a method parameter in place of a buffer before, other than when using the mbed classic rtos threading. It compiles fine, so if anyone can see the problem, I'd appreciate it.
Thanks
main.cpp
#include "mbed.h" #include "EthernetInterface.h" #include "UDPSocket.h" DigitalOut led1(LED1); EthernetInterface eth; UDPSocket udp; Serial pc(USBTX, USBRX); char msg[8] = "GusTest"; uint16_t port = 3648; const char addr[16] = "255.255.255.255"; int i; SocketAddress sAddr(addr, port); int main() { pc.baud(115200); pc.printf("\r\nStarting...\r\n"); i = eth.connect(); pc.printf("\r\nConnect code %d IP is: %s\r\n",i, eth.get_ip_address()); i = udp.open(ð); pc.printf("\r\nOpen code %d\r\n", i); i = udp.bind(sAddr); pc.printf("\r\nBind code for %s on port %d = %d\r\n",addr, port, i); while (true) { led1 = !led1; i = udp.sendto(sAddr, msg, sizeof(msg)); pc.printf("\r\nSend Code %d for %s size %d\r\n", i, msg, sizeof(msg)); wait(2); } }
Output
Starting... Connect code 0 IP is: xxx.xxx.xxx.xxx Open code 0 Bind code for 255.255.255.255 on port 3648 = 0 Send Code -3003 for GusTest size 8