Skip to content

Change to avoid attempting to read an Empty HTTP response on ESP32 #26

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 30, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions InfluxDb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand Down Expand Up @@ -163,11 +163,23 @@ boolean Influxdb::write(String data) {
Serial.print(" <-- Response: ");
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 + "\"");
}
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#####");
Expand Down