Go Down

Topic: Arduino Ethernet can't send more than 3 null bytes in a row? (Read 1 time) previous topic - next topic


I was trying to use an Arduino Ethernet to send an OSC packet to a program over UDP.
One of the requirements for OSC is that you're about to have up to 4 NULL bytes in a row to fill white space.
Apparently, when an Arduino sees 3 NULL bytes in a row, it cuts off all the rest of the data in the packet!
If you wan to see this for yourself, try this Arduino program I wrote.
Change the IP addresses to something sane, then fire up Wireshark, look at the packet when it gets sent, and you'll see that everything after byte 20 in the char array is missing.

I'm not trying to solve this problem any more as I found a different solution, but I thought I'd point this out as I think it's either a bug, or a limitation of the Wiznet chip.

Code: [Select]
This sketch receives UDP message strings, prints them to the serial port
and sends an "acknowledge" string back to the sender

A Processing sketch is included at the end of file that can be used to send
and received messages for testing with a computer.

created 21 Aug 2010
by Michael Margolis

This code is in the public domain.

#include <SPI.h>         // needed for Arduino versions later than 0018
#include <Ethernet.h>
#include <EthernetUdp.h>         // UDP library from: bjoern@cs.stanford.edu 12/30/2008

// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = { 
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192, 168, 1, 177);
IPAddress ip_remote(192, 168, 1, 100);

unsigned int localPort = 8888;      // local port to listen on

// buffers for receiving and sending data
char packetBuffer[UDP_TX_PACKET_MAX_SIZE]; //buffer to hold incoming packet,
char  ReplyBuffer[] = "acknowledged";       // a string to send back
//char oscBuffer[] = "/track2/connect ,i     1";
char oscBuffer[] = "/track2/connect ,i     1";

// An EthernetUDP instance to let us send and receive packets over UDP
EthernetUDP Udp;

void setup() {
  // start the Ethernet and UDP:

  Udp.beginPacket(ip_remote, 7000);
  oscBuffer[0] = 0x2f;
  oscBuffer[1] = 0x74;
  oscBuffer[2] = 0x72;
  oscBuffer[3] = 0x61;
  oscBuffer[4] = 0x63;
  oscBuffer[5] = 0x6b;
  oscBuffer[6] = 0x31;
  oscBuffer[7] = 0x2f;
  oscBuffer[8] = 0x63;
  oscBuffer[9] = 0x6f;
  oscBuffer[10] = 0x6e;
  oscBuffer[11] = 0x6e;
  oscBuffer[12] = 0x65;
  oscBuffer[13] = 0x63;
  oscBuffer[14] = 0x74;
  oscBuffer[15] = 0x00;
  oscBuffer[16] = 0x2c;
  oscBuffer[17] = 0x69;
  oscBuffer[18] = 0x00;
  oscBuffer[19] = 0x00;
  oscBuffer[20] = 0x00;
  oscBuffer[21] = 0x00;
  oscBuffer[22] = 0x00;
  oscBuffer[23] = 0x01;
  Serial.println(" ");
  for (int i=0; i<24; i++) {


void loop() {


The write with a character array pointer alone sends until it hits a zero terminator.
Code: [Select]
  // Change this
  // to this.

That should send 24 characters, zeros and all.

Go Up