From 2c58108dff1a841fd8344e747b30429b48f6e116 Mon Sep 17 00:00:00 2001 From: Chris Theberge Date: Sun, 29 Dec 2019 11:07:29 -0500 Subject: [PATCH 1/2] Avoid reading an empty HTTP response on ESP32 --- InfluxDb.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/InfluxDb.cpp b/InfluxDb.cpp index 4b098aa..1e79c29 100644 --- a/InfluxDb.cpp +++ b/InfluxDb.cpp @@ -47,7 +47,7 @@ void Influxdb::setBucket(String bucket) { } /** - * Set the influxDB port. + * Set the influxDB port. * @param port v1.x uses 8086, v2 uses 9999 */ void Influxdb::setPort(uint16_t port){ @@ -163,11 +163,21 @@ boolean Influxdb::write(String data) { Serial.print(" <-- Response: "); Serial.print(httpResponseCode); +#if defined(ESP32) + if (http.getSize() > 0) { + String response = http.getString(); + Serial.println(" \"" + response + "\""); + } + else { + Serial.println(); + } +#else String response = http.getString(); Serial.println(" \"" + response + "\""); +#endif boolean success; - if (httpResponseCode == 204) { + if (httpResponseCode == HTTP_CODE_NO_CONTENT) { success = true; } else { Serial.println("#####\nPOST FAILED\n#####"); From 044091308779081a8d713396f63d7298aa38d4f5 Mon Sep 17 00:00:00 2001 From: Chris Theberge Date: Sun, 29 Dec 2019 11:14:48 -0500 Subject: [PATCH 2/2] Add a comment explaining --- InfluxDb.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/InfluxDb.cpp b/InfluxDb.cpp index 1e79c29..804022f 100644 --- a/InfluxDb.cpp +++ b/InfluxDb.cpp @@ -164,6 +164,8 @@ boolean Influxdb::write(String data) { Serial.print(httpResponseCode); #if defined(ESP32) + // The ESP32 HTTP Lib seems to hang if you call getString if the server has not + // written anything in response. if (http.getSize() > 0) { String response = http.getString(); Serial.println(" \"" + response + "\"");