Hi all,
I hope someone will be able to help me with my issue. I am trying to send out an UDP packet but without any luck. The only instance when I send out the packet succesfully is when I first recieve an UDP packet and then send a reply to the same address as if the function first needed to know the way through network. But I need to send out a packet and then wait for the reply and I cannot figure out how to make this work. I have implemented the function that sends the packets just like mentioned in the examples including the check for successfull addres obtain from DHCP but no luck. Anyone please tell me where I am making a mistake.
Thanks, Radovan.
Take a look at the LEDSwitch and LEDClient examples. Enable the UDP port for communication.
I am afraid there is nothing wrong with the socket initialisation. Socket recieves data but I have problem sending data out. The only instance when I manage to send out the data is when I first recieve them from PC and then reply to the same address. Otherwise all attempts to send out UDP packet end up in an error.
My aim is to sned out an UDP packet with NTP request and wait for reply with time information.
Below is the code part for socket initialisation and the function where data is sent out.
init_TcpNet (); udp_soc = udp_get_socket (0, UDP_OPT_SEND_CS | UDP_OPT_CHK_CS, udp_callback); if (udp_soc != 0) { udp_open (udp_soc, 200); }
This is followed by the timer_poll() and main_TcpNet() endless loop.
Function to send data out:
unsigned char udp_msg[] = {"\111\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"}; U8 remip[4] = {192,168,1,154}; U8* sendbuf; U16 len;
if (mem_test (localm[NETIF_ETH].IpAdr, 0, 4) == __TRUE) { // IP address not yet assigned by DHCP. printf(" return "); return; }
len = strlen(udp_msg); sendbuf = udp_get_buf(len); str_copy(sendbuf, udp_msg); printf(" Alokace %d %d %d",sendbuf, sendbuf[0], udp_msg[0]); answer = udp_send(udp_soc, remip, 200, sendbuf, len);
Of course, strlen on a string containing zero bytes will fail.
That string is not empty. If I enter a text like "Hello world" inside the result is the same. If it was due to the zero string length I could never send the packet out. And as I wrote before I manage to send it out when I first recieve a packet from a certain address and then reply to the same address.
Use a debug version, enable UDP debug to Full debug and watch the debug print. You will see what is happening from the debug log.
Where do I set this? I am not quite sure what you mean by UDP debug and Full debug.
Take a look at the LEDClient example. There is a target defined for Debug. Check there how it is configured and do the same. In the Net_Debug.c enable UDP debugging to Full debug.
Thank you for the debug hint. There seems to be the problem on Ethernet layer:
ETH ERR: Unresolved MAC for IP: 192.168.1.154
This is the error I got.
Dear Franc,
can you tell me what to do in case of this error?
This is the reason why replying worked. The processor knew the MAC of the sending IP.
www.keil.com/.../rlarm_tn_using_udp_arpempty.htm