Skip to content

Commit 2c58108

Browse files
committed
Avoid reading an empty HTTP response on ESP32
1 parent 5cf6cc9 commit 2c58108

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

InfluxDb.cpp

Lines changed: 12 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,21 @@ boolean Influxdb::write(String data) {
163163
Serial.print(" <-- Response: ");
164164
Serial.print(httpResponseCode);
165165

166+
#if defined(ESP32)
167+
if (http.getSize() > 0) {
168+
String response = http.getString();
169+
Serial.println(" \"" + response + "\"");
170+
}
171+
else {
172+
Serial.println();
173+
}
174+
#else
166175
String response = http.getString();
167176
Serial.println(" \"" + response + "\"");
177+
#endif
168178

169179
boolean success;
170-
if (httpResponseCode == 204) {
180+
if (httpResponseCode == HTTP_CODE_NO_CONTENT) {
171181
success = true;
172182
} else {
173183
Serial.println("#####\nPOST FAILED\n#####");

0 commit comments

Comments
 (0)