Hi, can someone please advise on the correct method of catching connection error or failure in http.GET() requests? Just wondering if there's a builtin that I can use for a while statement to ensure any failure to connect will result in retry.
Current code. Note the credentials and tagMatch are global and cleared at the beginning of the function.
Thanks in advance!
void getRfidMatch() {
// Empty Credentials
loadID[0] = '\0' ;
hiveNum[0] = '\0' ;
boxNum[0] = '\0' ;
rfidMatchChar[0] = '\0' ;
tagMatch = false ;
char GET_URL[150] = "" ;
append("http://", GET_URL) ;
char IPChar[16] ;
serverIp.toString().toCharArray(IPChar, 16) ;
append(IPChar, GET_URL) ;
append("/rfid2hiveid_0.3_secure.php?", GET_URL) ;
// Format GET request
append2("api_key=", apiKeyValue, GET_URL) ;
append2("&pass=", sqlPass, GET_URL) ;
append2("&rfid=", sqlUID, GET_URL) ;
// Send formatted GET request
HTTPClient http ; // Declare object of class HTTPClient
http.begin(GET_URL);
int httpResponseCode = http.GET()
String payload = http.getString(); //Get the response payload
if (payload == "0 results") { // if there's no match, report
tagMatch = false;
return;
}
// If sql record returned form server
tagMatch = true ;
// assign variable values from payload
int payload_len = payload.length() + 1;
payload.toCharArray(rfidMatchChar, payload_len); // place returned ":" delimeted data into char arrays
http.end();
}
// If sql reqcord returned form server
tagMatch = true ;
// assign variable values from payload
int payload_len = payload.length() + 1;
payload.toCharArray(rfidMatchChar, payload_len); // place returned ":" delimeted data into char arrays
http.end();
}