Skip to content

Commit 93ab86a

Browse files
Merge pull request #26 from Encryptic/v2
Change to avoid attempting to read an Empty HTTP response on ESP32
2 parents 5cf6cc9 + 0440913 commit 93ab86a

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

InfluxDb.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ void Influxdb::setBucket(String bucket) {
4747
}
4848

4949
/**
50-
* Set the influxDB port.
50+
* Set the influxDB port.
5151
* @param port v1.x uses 8086, v2 uses 9999
5252
*/
5353
void Influxdb::setPort(uint16_t port){
@@ -163,11 +163,23 @@ boolean Influxdb::write(String data) {
163163
Serial.print(" <-- Response: ");
164164
Serial.print(httpResponseCode);
165165

166+
#if defined(ESP32)
167+
// The ESP32 HTTP Lib seems to hang if you call getString if the server has not
168+
// written anything in response.
169+
if (http.getSize() > 0) {
170+
String response = http.getString();
171+
Serial.println(" \"" + response + "\"");
172+
}
173+
else {
174+
Serial.println();
175+
}
176+
#else
166177
String response = http.getString();
167178
Serial.println(" \"" + response + "\"");
179+
#endif
168180

169181
boolean success;
170-
if (httpResponseCode == 204) {
182+
if (httpResponseCode == HTTP_CODE_NO_CONTENT) {
171183
success = true;
172184
} else {
173185
Serial.println("#####\nPOST FAILED\n#####");

0 commit comments

Comments
 (0)