The Freedom-K64F is an ultra-low-cost development platform for Kinetis K64, K63, and K24 MCUs.

mbed OS 5 - UDPSocket::sendto failing...

06 Feb 2017

Hi,

Im using the FRDM-K64F with the latest mbed OS 5 library, 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, so i'm not sure what i'm doing wrong. I suspected the issue was in my sendto() method usage, where the data buffer is of type 'const void *data'. I used a char array which compiled fine, but returned the above mentioned error code. I then tried casting the array as 'const void*', but the same thing returned.

I compiled the code for LPC1768, just to see if that would work, but that returns the same error code, which means its either the library or my code...

Can anyone who has used UDPSocket find an issue with the below code?

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(&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));
        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