Go Down

Topic: Error in the Ethernet Examples (Read 1 time) previous topic - next topic

pauljeff

Hi,
I'm brand new to the forums and relatively new to Arduino, but I think there may be some errors in a few of the Ethernet examples in the Learning section of the website.

For example, I bought an Eth shield recently and tried a few of the examples in the "Ethernet Library" section and the one titled "UdpNtpClient" does not work correctly.  I noticed it does not setup the Ethernet device correctly as it does not pass the subnet mask and gateway parameters correctly.  It only passes the mac and ip parameters as follows;

Ethernet.begin(mac,ip);

It should be along the lines of

Ethernet.begin(mac,ip,gateway,subnet);


and that is provided you have set both gateway and subnet earlier in your code.

For example I modified the example code as follows and it works fine.

<SNIP>
// 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 };
byte ip[] = {
  192,168,100,177 };
byte gateway[] = {
  192,168,100,254};   
byte subnet[] = {
  255, 255, 255, 0 };



unsigned int localPort = 8888;      // local port to listen for UDP packets

byte timeServer[] = {
  192, 43, 244, 18}; // time.nist.gov NTP server

const int NTP_PACKET_SIZE= 48; // NTP time stamp is in the first 48 bytes of the message

byte packetBuffer[ NTP_PACKET_SIZE]; //buffer to hold incoming and outgoing packets

void setup()
{
  // start Ethernet and UDP
  Serial.println("SETUP START");
  Ethernet.begin(mac,ip,gateway,subnet);
  Udp.begin(localPort);

  Serial.begin(9600);
  Serial.println("SETUP FINISH");
}
<SNIP>

as you can see I set the gateway and subnet variables to suit my home network, which is likely to be different to other people, but you get the drift.  I then make sure I pass those parameters in the Ethernet.begin call.

My apologies if someone has already pointed this out, but the example code on the website and in Arduino 0022 is still incorrect and may be causing people lots of heartache...it was a good learning experience fixing it myself though  :)

I think the problem exists in the Pachube example too, I will check that next.

By the way I think the whole Arduino thing is brilliant, I have got back into electronics based on this stuff (and am teaching my young kids), it is just such a class act.  Really well done guys.
Thanks,
Paul







DojoDave

I am submitting this to the documentation team, thanks ... it will be fixed asap

/d

Go Up