Welcome, Guest. Please Login or Register
Arduino: Forum
09.09.2010 at 08:11:54


Pages: 1 2 
Bug in Ethernet Library in new Arduino 0013 (Read 9257 times)
MFV
YaBB Newbies
*
Offline

Arduino rocks

Posts: 4

Bug in Ethernet Library in new Arduino 0013
07.02.2009 at 12:33:40
 
hi!

There is a bug in the Arduino 0013 Ethernet library.

A second connection to the same server doesn´t work. Only the first connection will work. Exact same code works fine in Arduino 0012.
I need the new float feature in the 0013 Ethernet libarary. So it would be nice if you fix it or release a work around. Thanks.

MFV

Back to top
 
 
View Profile   IP Logged
mellis
YaBB Administrator
*****
Offline



Posts: 3102
Cambridge, MA
Re: Bug in Ethernet Library in new Arduino 0013
Reply #1 - 07.02.2009 at 14:05:25
 
Can you post your code?  What happens when you try to make the second connection?
Back to top
 
 
View Profile | WWW   IP Logged
Digger450
Senior Member
****
Offline



Posts: 350

Gender: male
Re: Bug in Ethernet Library in new Arduino 0013
Reply #2 - 07.02.2009 at 22:32:54
 
I am having the same issue.  It hangs the Arduino completely on the second connection attempt.  Here is the code I am using:

Code:
#include <Ethernet.h>

// network configuration.  gateway and subnet are optional.
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 192, 168, 1, 178 };
byte server[] = { 192, 168, 1, 54 };

Client client(server, 13000);

long timerX = 31000;

void setup()
{
  // initialize the ethernet device
  Ethernet.begin(mac, ip);
  Serial.begin(9600);
  Serial.println("Ethernet ChatServer Online");
}

void loop()
{
  if (client.available())
  {
    while (client.available())
    {
      char c = client.read();
      Serial.print(c);
    }
  }
  
  long currentTime = millis();

  if (abs(currentTime - timerX) > 10000)
  {
    Serial.println(timerX);
    if (client.connect())
    {
      client.println("Arduino Rocks!");
      timerX = millis();
      Serial.println("Client Message Sent");
    }
  }
} 



Here is what I get back in the serial monitor:
Code:
Ethernet ChatServer Online

31000

Client Message Sent

ARDUINO ROCKS!

647 



I have a simple tcplistener running on my computer that echoes back whatever it receives.  As you can see it works on the first attempt and is about to attempt again after the 647.  But, that is it, nothing happens after that.  If the connect failed it should keep spitting out 647 until it connects because that value is not reset until a connection is made.  So it seems the Arduino simply hangs at that point.
Back to top
 
 
View Profile   IP Logged
mellis
YaBB Administrator
*****
Offline



Posts: 3102
Cambridge, MA
Re: Bug in Ethernet Library in new Arduino 0013
Reply #3 - 08.02.2009 at 13:51:30
 
Hmm, there were a couple of changes in the library, and it would be good to isolate which one caused the problem.

Can you change the following line in hardware/libraries/Ethernet/Client.cpp (in the Arduino application directory) from:

 socket(_sock, Sn_MR_TCP, _port, 1024 + _srcport);

to:

 socket(_sock, Sn_MR_TCP, _port, 0);

Then delete hardware/libraries/Ethernet/Client.o and try recompiling and re-uploading your sketch.  Do you see the same problem?
Back to top
 
 
View Profile | WWW   IP Logged
Digger450
Senior Member
****
Offline



Posts: 350

Gender: male
Re: Bug in Ethernet Library in new Arduino 0013
Reply #4 - 08.02.2009 at 21:31:54
 
I made the change, but it still hangs on the second connection.
Back to top
 
 
View Profile   IP Logged
kmm
YaBB Newbies
*
Offline

Arduino rocks

Posts: 3

Re: Bug in Ethernet Library in new Arduino 0013
Reply #5 - 08.02.2009 at 22:34:05
 
> Can you change the following line in hardware/libraries/Ethernet /Client.cpp (in the Arduino application directory) from:
>
>  socket(_sock, Sn_MR_TCP, _port, 1024 + _srcport);
>
> to:
>
>  socket(_sock, Sn_MR_TCP, _port, 0);

Should it not be

   socket(_sock, Sn_MR_TCP, 1024 + _srcport, 0);

that is as this modification to the Client.cpp is listed in the orginal message by a "Paul_", see the posting with the title

 "Ethernet Library Bug :: No Repeated Connections..."

on "page 2" on this forum?

I have not yet got around testing it myself though...

regards,


Back to top
 
 
View Profile   IP Logged
kmm
YaBB Newbies
*
Offline

Arduino rocks

Posts: 3

Re: Bug in Ethernet Library in new Arduino 0013
Reply #6 - 08.02.2009 at 23:14:49
 
Hi,

Tested it with the code above, but modified to use the standard "echo" service on port 7. Got a few TCP connection listed as open before the code somehow went into a "loop" writing the number "31075" to the serial console...

inetutils 15945        root    3u  IPv6  55938       TCP lupus.local:echo->10.0.0.177:1030 (ESTABLISHED)
inetutils 15946        root    3u  IPv6  55939       TCP lupus.local:echo->10.0.0.177:1031 (ESTABLISHED)
inetutils 16067        root    3u  IPv6  56394       TCP lupus.local:echo->10.0.0.177:1027 (ESTABLISHED)
inetutils 16068        root    3u  IPv6  56395       TCP lupus.local:echo->10.0.0.177:1028 (ESTABLISHED)
inetutils 16069        root    3u  IPv6  56396       TCP lupus.local:echo->10.0.0.177:1029 (ESTABLISHED)
inetutils 16072        root    3u  IPv6  56529       TCP lupus.local:echo->10.0.0.177:1025 (ESTABLISHED)
inetutils 16074        root    3u  IPv6  56567       TCP lupus.local:echo->10.0.0.177:1026 (ESTABLISHED)

regards,
Back to top
 
 
View Profile   IP Logged
mellis
YaBB Administrator
*****
Offline



Posts: 3102
Cambridge, MA
Re: Bug in Ethernet Library in new Arduino 0013
Reply #7 - 09.02.2009 at 10:22:36
 
kmm: I think you're right.  Does changing that line make it work better than with the default Arduino 0013 library?
Back to top
 
 
View Profile | WWW   IP Logged
kmm
YaBB Newbies
*
Offline

Arduino rocks

Posts: 3

Re: Bug in Ethernet Library in new Arduino 0013
Reply #8 - 09.02.2009 at 19:50:04
 
Hi,

Tested it with the original Client.cpp file and it do block, as originally reported by MFV.

Thinking of it it is not so strange as it with the line

  socket(_sock, Sn_MR_TCP, _port, 1024 + _srcport);

will create a new 5-tuple for the IP connection that is identical to the previous one. And that will not work. Changing the line into

  socket(_sock, Sn_MR_TCP, 1024 + _srcport, 0);

will on the other hand create a new unique 5-tuple (the originating port number changes) for the IP connection like it should do.

regards,
Back to top
 
 
View Profile   IP Logged
Digger450
Senior Member
****
Offline



Posts: 350

Gender: male
Re: Bug in Ethernet Library in new Arduino 0013
Reply #9 - 10.02.2009 at 07:37:53
 
Hi,

I tested kmm's fix and it seemed to do the trick.  But I was still having a problem my TCPListener program not receiving any subsequent messages because it still thought the first connection was open.  I was able to get around this by adding a client.stop() after sending a message.  Looking at it now it's probably better to use the client.connected() to see if you are still connected rather than creating a new connection each time.  It may still be a good idea to add:

Code:
  if (connected())
    stop(); 



or maybe:

Code:
  if (connected())
    return 1; 



to the begining of uint8_t Client::connect() in client.cpp?  What do you guys think?

I went ahead and modified the library to be compatible with Sanguino.  It tested fine with the modifications on both Arduino and Sanguino.

Good catch kmm!

Thanks guys.
Back to top
 
 
View Profile   IP Logged
MFV
YaBB Newbies
*
Offline

Arduino rocks

Posts: 4

Re: Bug in Ethernet Library in new Arduino 0013
Reply #10 - 10.02.2009 at 09:03:47
 
Hello again,

ich changed
 socket(_sock, Sn_MR_TCP, _port, 1024 + _srcport);
into
 socket(_sock, Sn_MR_TCP, 1024 + _srcport, 0);
in hardware/libraries/Ethernet /Client.cpp

recompile my sketch but Arduino still send one request and stop then. Hm...
Back to top
 
 
View Profile   IP Logged
halley
God Member
*****
Offline

Whatduino

Posts: 1035
Connecticut, US
Re: Bug in Ethernet Library in new Arduino 0013
Reply #11 - 10.02.2009 at 17:00:52
 
Whenever changing something in a library, remove all the *.o files in that library's folder.  Then recompile (verify) your sketch.
Back to top
 
« Last Edit: 10.02.2009 at 21:30:47 by halley »  
View Profile | WWW   IP Logged
MFV
YaBB Newbies
*
Offline

Arduino rocks

Posts: 4

Re: Bug in Ethernet Library in new Arduino 0013
Reply #12 - 10.02.2009 at 20:35:03
 
Fin, it works.
Great job. Thanks.
Back to top
 
 
View Profile   IP Logged
Dylan Bennett
YaBB Newbies
*
Offline



Posts: 5
Portland, Oregon
Gender: male
Re: Bug in Ethernet Library in new Arduino 0013
Reply #13 - 23.02.2009 at 18:38:05
 
Unfortunately, I spent an hour and a half up against this bug last night trying to figure out what I was doing wrong in my code. It didn't even occur to me that it might be a bug in the library. I figured it had to be my code, because, well, I'm new to this.

Glad to know it wasn't my code. An extra hour and a half of sleep would be nice, though.... Smiley
Back to top
 
 
View Profile | MSN | GTalk | ICQ | YIM | AIM   IP Logged
A.Selby
YaBB Newbies
*
Offline

I need more space
!!! Everyone is
closing in on me

Posts: 28

Gender: male
Re: Bug in Ethernet Library in new Arduino 0013
Reply #14 - 24.02.2009 at 05:57:52
 
I made those changes but I think I have another problem, after 5 connections (one after another ... not at the same time) ... the arduino refuses any connection for about a minute ? Is there something I should be calling to free up those connections, besides client.stop(); ?
Back to top
 
 
View Profile   IP Logged
Pages: 1 2