I'm trying to use the ethernet library to authorize rfid tags with a web server, I can get it to work the first time, but then each subsequent time it doesn't connect, i'm fallowing the client example on the arduino site. do i have to free the resources? or clear and create a new client object each time? i can't figure this out.
I have *** out some of my server info, sorry, the code isn't finished completely, but it does work.
Here is the loop:
Client client(server, 80);
void setup(){
setupRFID();
setupEthernet();
}
int counter=0;
int sizeClient = 0;
void loop(){
checkRFID();
if (client.available()) {
sizeClient = client.available();
for(int i=0;i<=sizeClient;i++){
char c = client.read();
Serial.print(c);
}
}
}
The checkRFID function waits for an rfid tag and when it reads one it sends the info to checkUser function. This all works the first time just fine, but if i tap a card after the first one, it doens't connect to the server, it just stays at connecting.
I never need to call Ethernet.Begin in loop, only in setup.
My arduino contacts my webserver every 15 seconds and has been doing so for over four weeks now.
I have a global Client and just call Client.connect() when needed, send the data and client.stop() at the end of data transfer.
The only thing that is different that I can see (I am away from my sourcecode right now, but will check tomorrow AM) is that you don't delay.
If you call client.print() and then immediately call client.stop() the webserver may not get the data. This happened to me a couple of times (but never on the first call...)
I do this instead.
// connect
// send header
// next line ends header:
Client.println();
delay(5)
Client.stop();
Hold on until I can get to my code and I will past the exact goods, but hopefully these suggestions will shake something loose until then.
I've worked on it and haven't made much progress. All of the ethernet stuff takes place in this one function, minus the ethernet setups. It is still working the first time and won't get passed the Serial.println("connecting...") if i try to call the function again. I'm not sure what is happening.
I think i solved my biggest issues. I've been reading forum posts for the good part of tonight, and came across a entry saying that client.h was filled with issues. And i must admit I am using a fairly old IDE version so I upgraded to a newer one and things seem to be working now. Although i'm still only partially there, now I have to parse the data.