6 years, 8 months ago.

socket not available for use

Hello,

I am trying to send UDP packages from one Nucleo767ZI board to another. On receiving board I am getting -3005 error.

Does anybody have idea what can be wrong?

Nucleo receiver

#include "mbed.h"
#include "lwip-interface/EthernetInterface.h"

DigitalOut led1(LED1);
DigitalOut led2(LED2);
DigitalOut led3(LED3);

static const char*          mbedIP       = "192.168.0.38";  //IP  
static const char*          mbedMask     = "255.255.255.0";  // Mask
static const char*          mbedGateway  = "192.168.0.3";    //Gateway

const int PORT = 50081;

EthernetInterface eth;

SocketAddress rd_addr;
UDPSocket rd_sock(&eth);

void receive()
{
   
     int bind = rd_sock.bind(PORT);

    char buffer[256];
    
    while(true){
    int ret = rd_sock.recvfrom(&rd_addr , buffer, sizeof(buffer));
    
    if(ret > 0){
    buffer[ret] = '\0';
    printf("Packet from \"%s\": %s\n", rd_addr.get_ip_address(), buffer);
    led3 = !led3;
    }

    else{
    printf("error %d\n", ret);
    led2=!led2;
    }
    }
    
}


int main() {

    Thread receiver;

    eth.set_network(mbedIP, mbedMask, mbedGateway);
    eth.connect();

    receiver.start(receive);

    while (true)
    {
        led1 = !led1;
        wait_ms(20);
    }
}

Thank you,

Daniel

I found what on mbed-os 5.5.4 UDP is not working. Program just keeps running after calling sendto() function or just stops on it if run it like a thread. Works on previous releases 5.5.3, 5.5.2

posted by Daniel Klioc 10 Aug 2017

1 Answer

6 years, 8 months ago.

We recommend using the latest version of EthernetInterface that is inside mbed OS now. Check out this documentation for some examples.

This example is mbed-os. I found problem what if you use printf in receive() thread it gets stuck or always too late to read data. If I delete printf`s, it starts to work, but after some time hangs in waiting data. Can it be something related with time out in Thread class?

posted by Daniel Klioc 09 Aug 2017