I am making a code that gets power information from a ted500 gateway. my code works fine until it fails to connect once. after that even though the connection should be happening every minute it will continue to fail and never recover.
here is the relevant(or what i think is relevant) code to this problem. the rest of my code is a mess so i wont post the whole thing unless necissary.
void getxml(){
// got = 1;
delay(1000);
if(debugxml == 1){
Serial.println("connecting...");
}
// if you get a connection, report back via serial:
if (client.connect()) {
got = 1;
resetcount = 0;
Serial.println("connected");
// Make call to TED500 to get LiveData
// http://TED5000/api/LiveData.xml
//http://TED5000/history/secondhistory.xml?MTU=1&COUNT=100&INDEX=10
char getRequest[100];
// strcpy(getRequest, "GET /history/secondhistory.xml?MTU=1&COUNT=100&INDEX=10");
// strcpy(getRequest, "GET /api/LiveData.xml");
strcpy(getRequest, "GET /history/minutehistory.xml?MTU=0&COUNT=10&INDEX=1");
strcat(getRequest, " HTTP/1.0");
client.println(getRequest);
// client.println("GET /search?q=arduino HTTP/1.0");
client.println();
// got = 1;
}
else {
// if you didn't get a connection to the server:
Serial.println("connection failed");
// got = 0;
}
if(debugxml == 1){
Serial.println("outget");
}
}
void loop(){
if(user == 1){
Serial.println();
Serial.println();
Serial.println();
Serial.println();
Serial.println();
Serial.println("type i to engage user interface");//allows the user to enter if statement below
user = 0;
}
if(Serial.read() == 'i'){//if the user types i enter interface void
delay(50);
interface();
}
// Serial.print("gettime1 ");
// Serial.println(gettime);
if (millis() >= gettime) {
getxml();
// Send next tweet 5 minutes from now
// Serial.print("gettime1.5");
// Serial.println(gettime);
gettime2 = gettime;
// Serial.println(gettime2);
gettime = gettime2 + 60000;
}
// Serial.print("millis ");
// Serial.println(millis());
// Serial.print("gettime2 ");
// Serial.println(gettime);
if(got == 1){
xml();
got = 0;
}
while(client.available()){
client.read();
}
if(!client.connected()){
// Serial.println("stop");
client.stop();
}
smoothing();//run the smoothing sequence
lightChange();//run the lighting change sequence
// Serial.println("hi");
}
the code works fine but i don’t know why it wont reconnect after it fails once.