Skip to content

write() takes 5 seconds, because it gets stuck at http.getString() #25

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

Closed
Cadence-GitHub opened this issue Dec 17, 2019 · 11 comments
Closed

Comments

@Cadence-GitHub
Copy link

I use the latest ESP8266-Arduino library (2.6.3). And the latest ESP8266_Influx_DB library (2.0.0).

When I execute the influx.write() call, it takes 5 seconds to complete. It gets stuck on this:
https://github.com/tobiasschuerg/ESP8266_Influx_DB/blob/5cf6cc93f6df73f18cebd6e06df79cc741002fe3/InfluxDb.cpp#L166

I use influxdb version 1.7.9.

@Cadence-GitHub
Copy link
Author

Here is how the output looks like when I execute the code on my ESP8266 device:

17:08:05.407 ->  --> writing to mysensors:
17:08:05.407 -> sound,device=5,sensor=2 value=1015
17:08:05.407 ->  <-- Response: 204 ""
17:08:10.623 -> 1021
17:08:10.826 -> 1021
17:08:11.028 -> 1021

That "1021" is a sensor read that normally happens every 200 milliseconds. You can see that it got stuck for 5 seconds after sending data to influxdb.

@Cadence-GitHub
Copy link
Author

Why do we even need this getString() here? Response code is what is really important here. Can we have a way to disable this getString() call when not needed?

@Cadence-GitHub
Copy link
Author

Perhaps this is how it should be fixed:

if (httpResponseCode != 204) {
   String response = http.getString();
   Serial.println(" \"" + response + "\"");
}

@tobiasschuerg
Copy link
Owner

Feel free to create PR

@ivanpiffer
Copy link

I use the latest ESP8266-Arduino library (2.6.3). And the latest ESP8266_Influx_DB library (2.0.0).

When I execute the influx.write() call, it takes 5 seconds to complete. It gets stuck on this:
https://github.com/tobiasschuerg/ESP8266_Influx_DB/blob/5cf6cc93f6df73f18cebd6e06df79cc741002fe3/InfluxDb.cpp#L166

I use influxdb version 1.7.9.

I'm exactly in the same situation. 5 seconds lost :(.
Have you found a solution as a patch of ESP8266HTTPClient ?
Or any possible solition in 2020 ?

13:38:19.052 -> --> writing to amperometri:
13:38:19.086 -> mA,device=amperometro,sensor=one,mode=pwm loopCount=863.00,value=118.50
13:38:19.154 -> mW,device=amperometro,sensor=one,mode=pwm loopCount=863.00,value=483.00
13:38:19.222 -> V,device=amperometro,sensor=one,mode=pwm loopCount=863.00,value=4.08
13:38:19.290 -> <-- Response: 204 ""
13:38:24.553 -> Current: 118.40 mA
13:38:24.553 -> Power: 482.58 mW
13:38:24.587 -> Voltage: 4.08 V

@ivanpiffer
Copy link

I use the latest ESP8266-Arduino library (2.6.3). And the latest ESP8266_Influx_DB library (2.0.0).
When I execute the influx.write() call, it takes 5 seconds to complete. It gets stuck on this:
https://github.com/tobiasschuerg/ESP8266_Influx_DB/blob/5cf6cc93f6df73f18cebd6e06df79cc741002fe3/InfluxDb.cpp#L166

I use influxdb version 1.7.9.

I'm exactly in the same situation. 5 seconds lost :(.
Have you found a solution as a patch of ESP8266HTTPClient ?
Or any possible solition in 2020 ?

13:38:19.052 -> --> writing to amperometri:
13:38:19.086 -> mA,device=amperometro,sensor=one,mode=pwm loopCount=863.00,value=118.50
13:38:19.154 -> mW,device=amperometro,sensor=one,mode=pwm loopCount=863.00,value=483.00
13:38:19.222 -> V,device=amperometro,sensor=one,mode=pwm loopCount=863.00,value=4.08
13:38:19.290 -> <-- Response: 204 ""
13:38:24.553 -> Current: 118.40 mA
13:38:24.553 -> Power: 482.58 mW
13:38:24.587 -> Voltage: 4.08 V

### SOLUTION

I've overwritten libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp with the version of the file you can find in caf891d316 tree here (not still accepted in the master ?) https://raw.githubusercontent.com/esp8266/Arduino/caf891d316a689bc5564a88a7796d7a8496345f5/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp

this is my output :) right now . ~ 1 seconds as my delay code delay(1000);
14:45:43.067 -> --> writing to amperometri:
14:45:43.101 -> mA,device=amperometro,sensor=one,mode=pwm loopCount=1113.00,value=118.90
14:45:43.169 -> mW,device=amperometro,sensor=one,mode=pwm loopCount=1113.00,value=484.61
14:45:43.237 -> V,device=amperometro,sensor=one,mode=pwm loopCount=1113.00,value=4.08
14:45:43.339 -> <-- Response: 204 ""
14:45:44.253 -> Current: 117.90 mA
14:45:44.253 -> Power: 480.53 mW
14:45:44.287 -> Voltage: 4.08 V
14:45:44.323 ->
14:45:44.323 -> --> writing to amperometri:
14:45:44.323 -> mA,device=amperometro,sensor=one,mode=pwm loopCount=1114.00,value=117.90
14:45:44.390 -> mW,device=amperometro,sensor=one,mode=pwm loopCount=1114.00,value=480.53
14:45:44.457 -> V,device=amperometro,sensor=one,mode=pwm loopCount=1114.00,value=4.08
14:45:44.559 -> <-- Response: 204 ""
14:45:45.476 -> Current: 118.70 mA
14:45:45.476 -> Power: 483.80 mW
14:45:45.510 -> Voltage: 4.08 V
14:45:45.544 ->
14:45:45.544 -> --> writing to amperometri:
14:45:45.578 -> mA,device=amperometro,sensor=one,mode=pwm loopCount=1115.00,value=118.70
14:45:45.645 -> mW,device=amperometro,sensor=one,mode=pwm loopCount=1115.00,value=483.80
14:45:45.712 -> V,device=amperometro,sensor=one,mode=pwm loopCount=1115.00,value=4.08
14:45:45.812 -> <-- Response: 204 ""
14:45:46.725 -> Current: 118.50 mA
14:45:46.725 -> Power: 482.98 mW
14:45:46.759 -> Voltage: 4.08 V

@thearduinoguy
Copy link

Will this solution mess up anything that uses the library?

@evanthomas
Copy link

I also hit this, although in my case it hangs indefinitely. Checking for 204 before calling getString() fixed it for me.

@ivanpiffer
Copy link

I also hit this, although in my case it hangs indefinitely. Checking for 204 before calling getString() fixed it for me.

Hi ! Can you show us your implementation? Thanks

@evanthomas
Copy link

@ivanpiffer I just changed the code in the function boolean Influxdb::write(String data) in file InfluxDb.cpp near line 166. I'm using platformIO so it recompiled it for me. Not whether the arduino IDE will do it automatically for you or not.

  String response;
  if (httpResponseCode == 204 ) {
    response = "";
  } else {
    response = " \"" + http.getString() + "\"";
  }
  Serial.println(response);

@tobiasschuerg
Copy link
Owner

This issue might be fixed with #26 and is contained in 2.0.1, please check.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants