Ethernet library -- Smaller and more functional

Hi all,

I'm wanting to make other people aware of the work Peter from tinker.it London has been doing on shrinking the size of the Ethernet library and adding additional functionality. The code is available here:

Arduino Ethernet2 library

Now, I'm pretty sure he wanted me to sign a whole load of disclaimers about it being untested before agreeing to me posting about it but I think it's important work and think others would be interested in trying it out.

I haven't yet tested it out but wanted to post about it before I forgot to do so again. :slight_smile:

--Phil.

Yes, please test it out and let me know how it works. I'd love to have a smaller library but didn't want to include it until it was tested (and I didn't have time to do it).

I've just used the Ethernet2 library for the first time and my sample code seemed to function the same as with the original Ethernet library. Obviously there could be some subtle incompatibly I'm not seeing but certainly IWFM at the moment.

Size difference:

7810 bytes (with Ethernet2)

10252 bytes (with original Ethernet)

So, currently a saving of ~2.5KB it seems.

Would be worth other people trying it out.

--Phil.

Yes, please. Anyone else?

Ethernet2 works great for me. I am also getting just over 2.5k smaller code compared to the official ethernet library.

for how long did you get the arduino working without a reset?
With the old libary I only get around 12 hours without a hanging, I hope this libary hasn't got this bug...

Thx
Geko

Hi Geko,

I didn't test uptime. Would you be able to test the Ethernet2 library with your project for us?

If you need assistance to do so, let us know. :slight_smile:

--Phil.

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 ?