Ethernet shield problems! Time to update library?

I have a similar problem try to read a slot counter+lap timer with a webserver

Our threat for details at: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1235245502/10#10

The fastest way to get these fixed would be if you can find the solution. For the problem of the connect() function returning 0 even though the connection succeeds, take a look at the Client::connect() code in ARDUINO/hardware/libraries/Ethernet/Client.cpp. The first question is which "return 0" is being called:

  if (!::connect(_sock, _ip, _port))
    return 0;

or:

  while (status() != SOCK_ESTABLISHED) {
    if (status() == SOCK_CLOSED)
      return 0;
  }

The second question is why. Maybe try adding a small delay between the call to connect() and the start of the while-loop? Or try looking for an intermediate status (SOCK_INIT) before starting that loop?

I'm not sure what to suggest for why the connection sometimes fails. It may be because when you reset the board, the connection is started from the same source port again. You could try editing Client::connect() to use a random _srcport.

Also, it appears that the disconnect (i.e. Client::stop()) sometimes fails. Here, it would be good to check the status() of the client after calling stop(). Be sure there's no data available().

Does that give you a place to start?

Here's my research and a fix (work-around) for the multiple client connect issue.

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

I'm not sure what to suggest for why the connection sometimes fails. It may be because when you reset the board, the connection is started from the same source port again. You could try editing Client::connect() to use a random _srcport.

I have watched the connection by tshark, it does connect from a different port at each reset. When using the local echo example the connection looks like this;

  3  17.126960  192.168.0.2 -> 192.168.0.3  ICMP Echo (ping) request
  4  17.127116  192.168.0.3 -> 192.168.0.2  ICMP Echo (ping) reply
 11  34.911229  192.168.0.2 -> 192.168.0.3  TCP 36588 > telnet [SYN] Seq=0 Win=5840 Len=0 MSS=1460 TSV=230615 TSER=0 WS=6
 12  34.911382  192.168.0.3 -> 192.168.0.2  TCP telnet > 36588 [RST] Seq=1 Win=0 Len=0

It does respond to PING requests, but it does not respond to any telnet requests.

When using the client example, the tshark output looks like this;

72 520.957368 de:ad:be:ef:fe:ed -> Broadcast    ARP Who has 192.168.0.2?  Tell 192.168.0.3
 73 520.957410 SamsungE_b0:47:e1 -> de:ad:be:ef:fe:ed ARP 192.168.0.2 is at 00:13:77:b0:47:e1
 74 520.957554  192.168.0.3 -> 192.168.0.2  TCP [TCP Port numbers reused] blackjack > http [SYN] Seq=0 Win=2048 Len=0 MSS=1460
 75 520.957605  192.168.0.2 -> 192.168.0.3  TCP http > blackjack [SYN, ACK] Seq=0 Ack=1 Win=5840 Len=0 MSS=1460
 76 520.957755  192.168.0.3 -> 192.168.0.2  TCP blackjack > http [ACK] Seq=1 Ack=1 Win=2048 Len=0
 77 520.995661  192.168.0.3 -> 192.168.0.2  TCP blackjack > http [FIN, ACK] Seq=1 Ack=1 Win=2048 Len=0
 78 520.995811  192.168.0.2 -> 192.168.0.3  TCP http > blackjack [FIN, ACK] Seq=1 Ack=2 Win=5840 Len=0
 79 520.995959  192.168.0.3 -> 192.168.0.2  TCP blackjack > http [ACK] Seq=2 Ack=2 Win=2048 Len=0

But when I check the Apache web server logs, there is nothing in there.

etracer came up with a workaround that works for me:

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

Thanks again!

I talked to our US Wiznet rep at ESC yesterday, but didn't get too far...they rotate someone from Korea every so often and it had just happened, he was only able to agree with everything I was saying :slight_smile:

I'll send an email, C is the universal language!

Hi, so I recently received the most excellent Arduino Mega and I'm having a bit of trouble interfacing it with the ethernet shield like I had hoped I could do. I can't seem to connect with it at all, though I can get a nice display of blinking LEDs while trying.

I have an older arduino NG.C board that I haven't yet tested the shield with (a friend is borrowing it) so my entire problem could be related to it.

My question stems from the fact that the ethernet shield is based on SPI and that the pins for the Mega for SPI seem to be different than the other boards. Could this be the cause of my problems?

Specifically, I will point to these two links:

and

For the mega, it says SPI is located on pins 50-53 and for the diecimila (pretty close to my Rev C I think) it says that SPI is located on pins 10-13.

Thank you in advance for any help you may provide.

Yeah, the SPI pins moving is going to be a deal breaker for the Ethernet shield, all existing Ethernet shields will have to be re-designed to work with the Mega.

all existing Ethernet shields will have to be re-designed to work with the Mega.

Or the SPI part of the code, which is conveniently abstracted already, can be rewritten to bit-bang the SPI for the MEGA.

-j

Because the Ethernet library needs to be even slower :frowning:

But lose the advantage of being hardware-based SPI in the process.

--Phil.

I've posted a completely revised Client portion of the Ethernet library. It includes many fixes and seems to resolve any connection issues or situations where a connection fails to completely close.

See here: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1238640832/0#0

Yeah, the SPI pins moving is going to be a deal breaker for the Ethernet shield, all existing Ethernet shields will have to be re-designed to work with the Mega.

Well, it sucks that I'm the one to find this out. I think a lot of folks are going to be disappointed that the ethernet shield isn't pin compatible with the Mega.

Would it be possible to move the pins physically to resolve this? The SPI connections on the mega are not under the ethernet shield so I would think that cutting off the header pins for 10-13 and then running wires from the headers to the SPI connection would resolve this issue. Would that require any modification to the Ethernet library to take care of the pin assignments?

:slight_smile:

-j

Smartprojects have this warning in their product description:

It has 53 IO (including 4 HW UARTs, 14 PWMs, I2C bus) and 16 Analog Input pins.
It can mount and use most of the Arduino Shields (not the ETH actual version).

http://www.smartprj.com/catalog/index.php?main_page=product_info&cPath=1&products_id=37

Perhaps this warning should be added to the Arduino Mega product page too...

Ok, I think the relevant section is located in the spi.h file inside of the utility folder of the ethernet library directory. I have no idea how to go about fixing it though. Am I way off? Could someone give me a hand in fixing this?

I just wanted to let everyone know that the ethernet shield is working great and it's being used in our custom web connected RFID cardreader system:

Thanks again for everyone who helped finding a quick solution for the connection problems!

The 35 second time out bug still appears every now and then, but for 99% of the time it's working perfectly!

Then for those who have problems with the ethernet card wich solution you propose

Because for all of us who are newbies this talk has lots of information but no practical solution

Thanks!

I'm working on a write-up about this project, I'll include links, code and schematics, but there are some other things that need my attention now..

There is a problem with the current version of the ethernet library, ports aren't closed properly so it runs out of available ports quickly.. Etracer came up with a good solution, see comment #16 of this thread.. His solution can be found here:

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

To get the RFID stuff up and running I used the code that Marc Boon posted last year:

http://trac.mediamatic.nl/picnic/wiki/RfiDuino

I'm interested on a ethernet solution to the connection problems

I'm working on a webserver put it in the arduino. My goal is to read some digital inputs and serve them to an iPhone with the GUI

But at this point I can't connect with the server

Thanks!