Pages: [1] 2   Go Down
Author Topic: Bug in Ethernet Library in new Arduino 0013  (Read 3258 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 4
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Logged

Forum Administrator
Cambridge, MA
Offline Offline
Faraday Member
*****
Karma: 12
Posts: 3538
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Can you post your code?  What happens when you try to make the second connection?
Logged

0
Offline Offline
Sr. Member
****
Karma: 0
Posts: 375
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Forum Administrator
Cambridge, MA
Offline Offline
Faraday Member
*****
Karma: 12
Posts: 3538
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

0
Offline Offline
Sr. Member
****
Karma: 0
Posts: 375
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I made the change, but it still hangs on the second connection.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 3
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

> 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,


Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 3
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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,
Logged

Forum Administrator
Cambridge, MA
Offline Offline
Faraday Member
*****
Karma: 12
Posts: 3538
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

kmm: I think you're right.  Does changing that line make it work better than with the default Arduino 0013 library?
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 3
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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,
Logged

0
Offline Offline
Sr. Member
****
Karma: 0
Posts: 375
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
« Last Edit: February 10, 2009, 02:35:11 am by Digger450 » Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 4
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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...
Logged

Connecticut, US
Offline Offline
Edison Member
*
Karma: 2
Posts: 1036
Whatduino
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Whenever changing something in a library, remove all the *.o files in that library's folder.  Then recompile (verify) your sketch.
« Last Edit: February 10, 2009, 03:30:47 pm by halley » Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 4
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Fin, it works.
Great job. Thanks.
Logged

Portland, Oregon
Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 28
I need more space !!! Everyone is closing in on me
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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(); ?
Logged

Pages: [1] 2   Go Up
Jump to: