7 years, 3 months ago.

UDP not working on K64F?


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.



#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] = "";
int i;
SocketAddress sAddr(addr, port);

int main()
    i = eth.connect();
    pc.printf("\r\nConnect code %d IP is: %s\r\n",i, eth.get_ip_address());
    i = udp.open(&eth);
    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));



Connect code 0 IP is: xxx.xxx.xxx.xxx

Open code 0

Bind code for on port 3648 = 0

Send Code -3003 for GusTest size 8
Be the first to answer this question.