(Sorry for my English, I'm french)
I have a problem with a httpClient function.
It managed to connect to the server. Then when it comes time to read the data, after a while, the client receives "NOT CONNECTED", then nothing.
Do you have any idea why?
My code :
String * httpClient (const String txt) {
IPAddress server(192,168,1,220);
String retour[] = { "", "", ""};
int iVar = 1;
boolean startRead = false;
int iterations = 0;
Serial.println("Trying to connect");
if (client.connect(server, 80)) {
Serial.println("Connected");
client.print("GET /RFID.php?code=");
client.print(txt);
client.print(" HTTP/1.1\r\n");
client.print("HOST: 192.168.1.220");
client.print("\r\nConnection: close\n\r\n");
while(client.connected()) {
Serial.print(".");
if (client.available() > 0) {
char c = client.read();
Serial.print(c);
if (c == '<' ) {
startRead = true;
}
else if(startRead){
if(c != '>'){
retour[iVar - 1].concat(c);
}
else{
Serial.print("Variable recue : "); Serial.println(retour[iVar - 1]);
startRead = false;
iVar += 1;
if (iVar == 4) {
Serial.println("disconnecting(0)");
client.flush();
client.stop();
return retour;
}
}
}
}
if (iVar == 2 && startRead == false) {
iterations ++;
if(iterations > 10) {
client.flush();
client.stop();
return retour;
}
}
}
}
Serial.println("NOT CONNECTED..");
client.flush();
client.stop();
Serial.println("DONE! FLUSH/STOP.");
}
Then this is what appears in the console:
Trying to connect
Connected
...HNOT CONNECTED..
DONE! FLUSH/STOP.