Pages: [1]   Go Down
Author Topic: Arduino losses connection with server (Apache Tomcat)  (Read 791 times)
0 Members and 1 Guest are viewing this topic.
Argentina
Offline Offline
Newbie
*
Karma: 0
Posts: 10
the keeper
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello smiley

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

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 547
Posts: 45935
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
We have an Arduino
There are roughly a dozen models. You have which one?

Quote
with an RFID card reader
Which one?

How is it connected?

Quote
which sends the RFID tag
How does it get it?

Quote
The first connection to the server -in which the Arduino sends "I'm ready" via GET- is made flawlessly.
Why is it doing this?

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

Argentina
Offline Offline
Newbie
*
Karma: 0
Posts: 10
the keeper
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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:

Quote
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)

Quote
Quote
with an RFID card reader
Which one?

How is it connected?

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

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

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

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

Quote
What does your code look like?

Code:

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();
}
« Last Edit: November 23, 2012, 01:56:42 pm by Janitro » Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 547
Posts: 45935
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

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

Miramar Beach, Florida
Offline Offline
Faraday Member
**
Karma: 115
Posts: 5356
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Argentina
Offline Offline
Newbie
*
Karma: 0
Posts: 10
the keeper
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Pages: [1]   Go Up
Jump to: