Hi,
I have a MKR1000 which controls my irrigation system.
The only problem I have is that when the connection is lost, it won't try to reconnect.
This is the code I have. Can someone point me to what I'm doing wrong?
([...] are some variables I removed from this post)
void loop(){
[...]
int err =0;
digitalWrite(LED_BUILTIN, HIGH);
delay(1000);
digitalWrite(LED_BUILTIN, LOW);
delay(1000);
err = http.get(kPathClone);
if (err == 0) {
//Serial.println("startedRequest ok");
err = http.responseStatusCode();
if (err >= 0) {
int bodyLen = http.contentLength();
String response = http.responseBody();
setOperation(response, 0);
unsigned long timeoutStart = millis();
char c;
// Whilst we haven't timed out & haven't reached the end of the body
while ((http.connected() || http.available()) && (!http.endOfBodyReached()) && ((millis() - timeoutStart) < kNetworkTimeout) ){
if (http.available()){
c = http.read();
// We read something, reset the timeout counter
timeoutStart = millis();
}else{
// We haven't got any data, so let's pause to allow some to
// arrive
delay(kNetworkDelay);
}
}
}else{
Serial.print("Getting response failed: ");
Serial.println(err);
}
}else{
Serial.print("Connect failed: ");
Serial.println(err);
}
http.stop();
// And just stop, now that we've tried a download
delay(15000);
}