Arduino losses connection with server (Apache Tomcat)

Hello :slight_smile:

We have an Arduino with an RFID card reader, which sends the RFID tag to an Apache Server (in order to validate the user).

The first connection to the server -in which the Arduino sends "I'm ready" via GET- is made flawlessly. But, when the Arduino reads the RFID card, it cannot send back the message to the server; it drops the connection and stays on "Connecting to server..." We see this with the Serial Monitor.

We are aware of an issue similar to ours: Ethernet fails connecting after a while. But the fix posted on that thread didn't resolve our issue.

Thanks!

We have an Arduino

There are roughly a dozen models. You have which one?

with an RFID card reader

Which one?

How is it connected?

which sends the RFID tag

How does it get it?

The first connection to the server -in which the Arduino sends "I'm ready" via GET- is made flawlessly.

Why is it doing this?

But, when the Arduino reads the RFID card, it cannot send back the message to the server

Back to the server? Did the server ask it to read the RFID card? Servers don't generally ask clients to do stuff. So, the client is sending a response back.

If it is sending a GET request, with an RFID tag, that is a different story.

What does your code look like?

Thanks for your reply! I realized I was somewhat vague with my question and I also explained it wrong....

The fact is, the Arduino reads the RFID card and sends the message just fine. The server receives the RFID tag and validates the user. The issue appears when the Arduino moves on to detect the presence of an object with an Ultrasound Sensor. That is when the Arduino losses the connection to the server...

Here's the addition info:

PaulS:

We have an Arduino

There are roughly a dozen models. You have which one?

We have an Arduino UNO (Rev 3) with an Ethernet Shield (also Rev 3)

with an RFID card reader

Which one?

How is it connected?

It's a Sparkfun ID-12 RFID Reader, connected to pin 0 (RX)

which sends the RFID tag

How does it get it?

It gets the tag via the ID-12 reader, the Arduino detects there is a card and then sends the HEX code to validate the existence of the card. The server then replies if the card (hence the user) is allowed to move on or not.

If the user is allowed, the Arduino carries on to detect the presence of an object (with an HC-SR05 Ultrasound Sensor, connected to pins 5 and 6). This is when the connection to the server is lost, and the Arduino is unable to send that info. It just hangs...

The first connection to the server -in which the Arduino sends "I'm ready" via GET- is made flawlessly.

Why is it doing this?

This is being done to let the server know when is the Arduino ready to begin reading cards and validating users.

But, when the Arduino reads the RFID card, it cannot send back the message to the server

Back to the server? Did the server ask it to read the RFID card? Servers don't generally ask clients to do stuff. So, the client is sending a response back.

If it is sending a GET request, with an RFID tag, that is a different story.

Yes, it is sending a GET request with the RFID card as string. The server waits for the string and validates the user.

What does your code look like?

Code:

boolean sendMessage(String aMessage){
    boolean isConnected = connectToServer();
    if (isConnected){
      Serial.println("Conection established"); 
      client.println(aMessage);
      client.println();
      Serial.print("Message sent: ");
      Serial.println(aMessage);
    }
    else {Serial.println("Conection fail timeout");}
   return isConnected;
}

// Connects to the server 
boolean connectToServer(){
    Serial.println("Connecting to server...");
    client.connect(server, PORT);
    int attemptNumber = 0;
    boolean stillTimeOut = attemptNumber < MAX_ATTEMPS;
    boolean cantConnect = !client.connected() & stillTimeOut;
    while (cantConnect){
      stillTimeOut = attemptNumber < MAX_ATTEMPS;
      cantConnect = !client.connect(server, PORT); & stillTimeOut;
      attemptNumber++;
      Serial.print("Conecting... Attempt number: ");
      Serial.println(attemptNumber);
    }
    return client.connected();
}

This is being done to let the server know when is the Arduino ready to begin reading cards and validating users.

Client/server connections are stateless. The fact that a client somewhere told the server that it was ready and another client sent a RFID tag would not tell the server anything about whether the two clients were the same. Sending "I'm ready" seems pointless.

The server waits for the string and validates the user.

No, the server isn't waiting for that string. It is doing other things, and simply notices that a client has made a request.

The code you posted fails to compile.

sketch_nov23a.cpp: In function 'boolean sendMessage(String)':
sketch_nov23a:4: error: 'client' was not declared in this scope
sketch_nov23a.cpp: In function 'boolean connectToServer()':
sketch_nov23a:16: error: 'client' was not declared in this scope
sketch_nov23a:16: error: 'server' was not declared in this scope
sketch_nov23a:16: error: 'PORT' was not declared in this scope
sketch_nov23a:18: error: 'MAX_ATTEMPS' was not declared in this scope

You should post all your code as PaulS suggests.

In the meantime, try this web client code. It has all the fixes I know of, and has been well tested.
http://www.arduino.cc/playground/Code/WebClient
Run it for a while to insure it continues to establish a connection.

Thanks for your suggestions!

The WebClient example works fine.

Here's the whole code, but it won't compile either because we use other libraries.

http://dl.dropbox.com/u/1334728/Automatic.ino

"CheckFillManual" works fine, the Arduino sends the info across the network just fine.