Browse Source

make httpclient retry

lightsleep
Hendrik Langer 7 years ago
parent
commit
f9e954b3d8
  1. 33
      src/main.cpp

33
src/main.cpp

@ -174,25 +174,30 @@ void ICACHE_FLASH_ATTR sendValues() {
char buffer[500]; char buffer[500];
array.printTo(buffer, sizeof(buffer)); array.printTo(buffer, sizeof(buffer));
HTTPClient httpclient; int httpCode = 0;
char url[100]; for (int tries=0; tries<3 && httpCode != HTTP_CODE_CREATED; tries++) {
sprintf(url, "http://%s/boxes/%s/data", server, SENSEBOX_ID);
httpclient.begin(url); HTTPClient httpclient;
httpclient.addHeader("Content-Type", "application/json"); char url[100];
sprintf(url, "http://%s/boxes/%s/data", server, SENSEBOX_ID);
int httpCode = httpclient.POST(buffer); httpclient.begin(url);
httpclient.addHeader("Content-Type", "application/json");
if (httpCode > 0) { httpCode = httpclient.POST(buffer);
if (httpCode == HTTP_CODE_CREATED) {
httpclient.writeToStream(&Serial); if (httpCode > 0) {
Serial.println(); if (httpCode == HTTP_CODE_CREATED) {
} else { httpclient.writeToStream(&Serial);
Serial.printf("[HTTP] POST... failed, error: %s\n", httpclient.errorToString(httpCode).c_str()); Serial.println();
} else {
Serial.printf("[HTTP] POST... failed, error: %s\n", httpclient.errorToString(httpCode).c_str());
}
} }
}
httpclient.end(); httpclient.end();
}
WiFi.disconnect(); WiFi.disconnect();
WiFi.mode(WIFI_OFF); WiFi.mode(WIFI_OFF);

Loading…
Cancel
Save