Hello everyone!
I'm currently using Keil uVision 5 in order to program an UDP interface in order to communicate with another machine on my local network.
While the reception of messages via the configured UDP Socket work, the sending of messages does not appear to work, as I recieve a "netError" value on the netStatus value that the netUDP_Send() function returns. Based on the reference, this error simply states that the sending failed. I was not able to find any explanation as to why I am getting this error. Do you have any ideas or suggestions?
Here is a sample of the code I use to recieve and send the UDP messages (I am trying to send form the local 10000 UDP Port, to my computer's 61345 UDP port, whose IP adress is 192.168.1.72 :
NET_ADDR addr = { NET_ADDR_IP4, 61345, 192, 168, 1, 72}; int8_t start(void){ int32_t socket = netUDP_GetSocket(udp_receive_callback); if(socket >= 0){ //Le socket est bien alloué if(netUDP_Open(socket,10000) == netOK){ uint8_t *sendbuf; sendbuf = netUDP_GetBuffer(1); sendbuf[0]=0x65; netStatus status = netUDP_Send(socket,&addr,sendbuf,1); if(status == netOK) return 1; else{ return -1; } } else return -1; } return -1; }
You might try
NET_ADDR4 addr = { NET_ADDR_IP4, 61345, 192, 168, 1, 72};
NET_ADDR addr = { NET_ADDR_IP4, 61345, 192, 168, 1, 72};
Thanks for the suggestion, but it didn't change much.
You could wait until you get a valid IP address assigned after the link is up.
Try the following:
uint32_t addr; netInitialize(); do { osDelay(500U); netIF_GetOption(NET_IF_CLASS_ETH | 0, netIF_OptionIP4_Address, (uint8_t *)&addr, sizeof (addr)); } while (addr == 0U);