Questions with UPD packets

Hello,

I have 2 questions actually:

  • I need to send a long message through UDP, around 500 characters. The default limit of udp_tx_packet_max_size is 24, would be any problem making it 500 bytes big?

  • When I print the received message, it shows some garbage too, even for the first time the program uses the packetBuffer. I tried to set the buffer to ‘\0’, but it still prints an extra line. I assume it is printing the whole buffer all the time. (I cannot test it now, but I guess that if I add an “end of line” to the message, it should print till that, right?)

thanks!

I haven’t tried 500 bytes, but I don’t see a reason you can’t.

I don’t know what you mean by an extra line. It should send the packet no matter what is in it. It can contain binary or text. If text, the text normally would require a zero terminator.

I mean something like this


hello
some garbage here


And if I set the buffer to '\0':


hello


It doesn't print just "hello".

Post your code.

What program are you using to receive the UDP packet?

I was using the example within the IDE: http://arduino.cc/en/Tutorial/UDPSendReceiveString

I am testing communications now, but my project will be an Arduino Ethernet and an Intel Galileo, communicating each other via UDP messages, beeing Galileo who sends 500 chars, and Ethernet receiving it.

So that post above is the printout of the packet received by the Arduino ethernet? If so, what does it show for "Received packet of size "?

It doesn't look the same when I copy it, so I uploaded the picture :wink:

This was the first message, and it shows already garbage.
I'm using netcat from linux to send the messages

I found the problem.

I experienced some problems with "print", so I don't like to use this very much (after 5 consecutives prints, another project failed, and it took long time to realise it was the "print"), and since then I use println instead.

We must set the content of the buffer to 0 (using a for), and we must change "println" for "print", since "println" prints an extra line at the end of our message.

With those changes I'm not experiencing problems anymore, but I think there still is some kind of bug with print and printline.

The print and println functions do not have a bug, at least from my experience. I have used both thousands of times without any problems at all.

And yes, println prints a carriage return/line feed after the data. That isn't "extra".

edit: The only time it appears that either has a "bug" would be if there is no terminating zero at the end of the string, causing both functions to continue printing characters until a zero byte is reached. That is not a problem with print or println.