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.
8 years, 2 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(ð);
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
1 Answer
8 years, 2 months ago.
We recommend using the latest version of EthernetInterface that is inside mbed OS now. Check out this documentation for some examples.
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