Ethernet library -- Smaller and more functional

Thx Phil

I just starated the projrct and I will give you some feedback when something strange happend...

Thx
Geko

I would love to test it ... just have a quick question ... If I copy the client, server, ethernet2, and print files to a folder named ethernet2 in my libraries folder then all I have to do is change the #include <Ethernet.h> to #include <Ethernet2.h> ???

To make this easier for people to try I out I have exported revision 43 of the code from the SVN repository and zipped it up*.

You should be able to unzip the archive and then place the Ethernet2 folder and content in your libraries directory. Then you can change your include line to be Ethernet2 and it should work.

Here is the Ethernet2 library zip file.

--Phil.

  • I used svn export http://tinkerit.googlecode.com/svn/trunk/Ethernet2\ library tinkerit-ethernet2-read-only to do so.

hmm after 7 hours the arduino does hang.... But why????

This is my code:

#include <Ethernet2.h>

byte mac[] = { 
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 
  192, 168, 0, 177 };
byte server[] = { 
  111, 111, 111, 111 };
unsigned long lastmillis = -300000;
long sek = 300;
int s1;
float s2;
int s3;
int incomingByte;
int count_i = 0;
Client client(server, 80);

void setup(){
  Ethernet.begin(mac, ip);
  Serial.begin(9600);
  Serial.println("Start!");  
  delay(1000);
}

void loop(){  


  if (millis() >= (lastmillis + (sek * 1000))){ 
    Ethernet.begin(mac, ip);
    if (client.connect()){
      client.print("GET MYSITE/daten_mysql.php?s1=");
      s1 = (analogRead(0) * 1000.0)/1023.0;
      if ((long)s1 >= 50){        
        client.print((long)s1);
      }
      else{
        client.print("0");
      }
      client.print("&s2=");
      s2 = ((((analogRead(1) * 1000.0)/1023.0)/(1000.0))*222.22)-61.11;
      client.print((long)(s2*10));
      client.print("&s3=");
      s3 = ((((analogRead(2) * 1000.0)/1023.0)/1000.0)*190.6)-40.2;
      client.print((long)(s3*10));
      client.println();
      lastmillis = millis();
    }
  }

}

The loop funcion is quite easy. As soon as 5 minutes are over arduino is going to a Webpage with a MYSQL Database and stores 3 Sensor values to this Database. That's it.
What's wrong about that???

Thx
Geko

I wonder if you are running Arduino 0011 and millis is overflowing.

Anyway, why not replace:
if (millis() >= (lastmillis + (sek * 1000)))
with
delay(sek * 1000) ;

thx, but I think it isn't a millis overflow. Yes I use the Arduino 0011 does this one have a problem with millis()??

Thx
Geko

As I recall millis() overflowed after 9 hours in Arduino 0011. Why not try to use delay instead, if only see if that makes the problem go away.

ok this migth work but I got further code... For example an XBee wich is receiving data from other stations...
And the server will answer to the data I sent...

Geko

I'm bummed ... I was hoping that this new ethernet library would solve my problem ... It didn't after five connections the Arduino the arduino actively refuses the next connection.

I have the information about my program:

http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1234006420

(Most of it is on the second page)

The long and short of it is ... I have a .net app on my computer that sends IR timing pairs to the arduino then it flashes a IR led ... if I wait a min or so between commands it works ... but I want to turn a ipaq in to a remote ... any ideas would be very helpful ... it anyone has any ideas why it would work four or five times then stop working for a min ???

The Ethernet library only supports 4 connections at once. So if the connections are being disconnected right away, you might be using them all up.

is there any way to close those connections when I'm done with them ... I'm sure thats what happening ... Or do I have to wait for it to timeout/close them its self

You can use client.stop().

yeah, I am using client.stop() and I still get the same issue ... its like it doesn't do anything ?

Are there any known problems with the ide version 13 and ethernet2?
Before I start posting up code I just wanted to see if anyone else has used ide ver13 or if its just my fiddling that has broken it.

Im getting multiple definitions from the arduion core print.cpp and the ethernet2 print.cpp stuff.

Thanks

Gordon

I had the same problem with the print.cpp ... I just removed the old print from the core folder ... and everything seems to be working great ...

Hasnt that got a knock on effect for other libraries?
Or does the Ethernet2 print.cpp take over and serial.print and others use that?

Gordon

everything seems to be working so far ... serial.print and all

For what it's worth, I've had a sketch running with the Ethernet2 library for 18 hours. The sketch does a TCP connect/read/close cycle and the Duemillanove on which it is running is still going strong after 254,000 connects.

As an aside, the Ethernet library of arduino-0015 still borks after four connect/close pairs.

As an aside, the Ethernet library of arduino-0015 still borks after four connect/close pairs.

See here for a revised version that corrects the connection problems (and fixes a number of other bugs).

And note that the Client.cpp in the Ethernet2 library is basically identical to the one included in the "standard" library (meaning it has the same bugs).

That seems to work. Thank you.

BTW, with Ethernet2 I get 6064 bytes (of a 30720 byte maximum). The "new" Ethernet is a bit larger than that: same sketch comes in at 7486 bytes.