Ethernet library modification

hi,
I'm trying to do a web server with an arduino + ethernet shield, but this is very slow, I think that I can speed up the communication between arduino and PC if I can modify the Ethernet library.
In the folder of ethernet/utility there is a couple of files: W5100.cpp and W5100.h and I've tried to modify:
#define TX_RX_MAX_BUF_SIZE 2048 -> #define TX_RX_MAX_BUF_SIZE 4096
writeTMSR(0x55); writeRMSR(0x55); -> writeTMSR(0x06); writeRMSR(0x06);
#define MAX_SOCK_NUM 4
I found some information in " http://forum.arduino.cc/index.php/topic,44524.0.html " but it seems old, I think that I'm near of the solution... :slight_smile:

Can anyone help me?

Thanks.

That is the size of the internal buffer for the w5100. Unless you have a custom w5100 IC, that will probably cause a fail.

There are other ways to improve performance. The most efficient way is to send data packets with more than one or two characters in them. Here is an example of a client http request.

// this sends the request in 4 packets, 
// the last packet contains only a carriage return/line feed
client.println("GET / HTTP/1.1");
client.println("Host: www.mydomain.com");
client.println("Connection: close");
client.println();

// this sends exactly the same request all in one packet.
client.println("GET / HTTP/1.1\r\nHost: www.mydomain.com\r\nConnection: close\r\n");

edit: If you use the SD in conjunction with the w5100, here is a topic that might interest you. It shows how to buffer the SD reads to send them in 64 byte payload packets.
http://forum.arduino.cc/index.php?topic=134868.0

Thanks SurferTim for you answer, I saw in the link that zoomkat gets about 20 KB/s using buffer and now I'm getting the same rate.
But I still think that is possible improve the speed,I see that WIZnet W5100 chip have 16 KB of internal memory for TX/RX buffers (http://www.wiznet.co.kr/Sub_Modules/en/product/Product_Detail.asp?cate1=&cate2=&cate3=&pid=1011) and in the datasheet of W5100 (http://www.wiznet.co.kr/UpLoad_Files/ReferenceFiles/W5100_Datasheet_v1.2.4.pdf) it say the way to set the size of the buffers (page 38 and 39) and how we can see in ethernet/utility/W5100.cpp and W5100.h (these files are in arduino's compiler) that arduino settings are for 4 sockets and 2K memory per socket, I think that if we can change this setting for 4 sockets but 4K,2K,1K,1K memory per socket, we can improve the rate transfer, in my attempt I got double speed but no stability (the begining of the file is ok and after garbage data...)
It seems that this is possible because Mavromatis says that he can ( Wiznet W5100 (Ethernet Shield) Buffer Question. - Interfacing - Arduino Forum ) but this post is old and the actual library of Ethernet is not exactly the same.
Any help is welcome :slight_smile:

arduino settings are for 4 sockets and 2K memory per socket, I think that if we can change this setting for 4 sockets but 4K,2K,1K,1K memory per socket, we can improve the rate transfer, in my attempt I got double speed but no stability (the begining of the file is ok and after garbage data...)

I am not surprised at all, especially if any UDP functions are being used, like dhcp, dns, ntp. One of those could get your big socket. Then the library will use the next socket. You can end up rotating through all the sockets over a period of time.

You could modify the crap out of this library, or write your own, that uses specifically that one socket. But then you are limited to that one socket for your "big stuff".

Hi,
After several attempts, it seems that the options are : 4 sockets with 2k per buffer or 2 sockets with 4k per buffer in my benchmarks it seems that it isn't improvments, maybe to upload files to arduino (I get double speed but maybe is cause of " curl.exe "), so at the end, the conclusion is that is not woth to change the ethernet library.
Bye.

(I get double speed but maybe is cause of " curl.exe ")

What does curl.exe have to do with the arduino? Something missing here.

Hi zoomkat,
I apologize if I'm not clear in my post (The English in not my native languaje).
My project is a server for domotic purpose, and I use a web browser and a Phonegap application (Android) to interact with the arduino (server).
When I use the Phonegap application the webpages and photographs are in the phonegap application and I don't need to download to the phone any data from the arduino, but when I use a web brower all data is downloaded from the arduino and this is slow (in my opinion). This low speed is the cause for look an improvement of the speed of the ethernet library.
When I want to upgrade the webpage stored in the uSD card I use the curl.exe command.
My server is inspired / copied of Tiny Web Server (http://www.webweavertech.com/ovidiu/weblog/archives/000484.html) this software is too huge for my purpose and I've modified it for my needs, in this process I saw that the time to download data isn't the same to upload ¿why to download data is faster than upload?.
Increasing the RX buffer x2 of the Ethernet library I need /2 less time to upload, great!!! so ... ¿if I increase the TX buffer x2 can I decrease /2 the time to download? The sad response is not.
After these testings my conclusion is that web browser is not sensitive to buffer size but the curl.exe yes it is, so maybe the way to work of curl.exe is less efficient than a web browser (maybe I'm wrong).
Now I'm thinking to use the web browser to upload data, but I don't find anything... at this moment.

If you are thinking about modifications of the Ethernet library, I have one thing I would like to have help with.
When my Arduino web-server receives a connection from a web browser, it gets two connections, one for the page and one for favicon.ico. My server can respond to both, which works sometimes. But most often I think that both connections gets closed when, at the end of the web page, client.stop() is sent to the w5100.
This makes the web browser to "never" be finished loading the web page from the Arduino.

Please correct me if I am the only one experiencing this.

My code works fine with the page request and the favicon request. It doesn't return a favicon.ico file, but the web browser finishes the download.
http://playground.arduino.cc/Code/WebServerST

The requests for each file will use separate sockets. Closing one will not close the other.

Thanks for the tips. I changed my code not to send stop until it has been silent on the line for some time. The web browser waits until I send client.stop() before it says the page is ready.

Now my page works better with Internet Explorer, but Firefox still asks for the icon two or three times. I made FF stop doing that by setting Cache-Control: max-age=2678400.

But any browser in my Android still has problems knowing my simple page has been loaded and shown to the user. To me it seems that I should send something to the client that let it know that the web-page has been sent and nothing more is to come from the server. Now is the client notified by the fact that the server closes the connection. Can I send something stating that? I don't mind keeping the connection up for a minute or so, because I don't expect others to connect to my server.

To me it seems that I should send something to the client that let it know that the web-page has been sent and nothing more is to come from the server.

There is.

client.stop();

That causes the client to exit this while(client.connected()) loop.

while(client.connected())
  {
    while(client.available())
    {
      inChar = client.read();
      Serial.write(inChar);
      // set connectLoop to zero if a packet arrives
      connectLoop = 0;
    }

    connectLoop++;

    // if more than 10000 milliseconds since the last packet
    if(connectLoop > 10000)
    {
      // then close the connection from this end.
      Serial.println();
      Serial.println(F("Timeout"));
      client.stop();
    }
    // this is a delay for the connectLoop timing
    delay(1);
  }