-
Notifications
You must be signed in to change notification settings - Fork 13.3k
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
ESP8266HTTPClient error -1 #6180
Comments
Please don't post links to external sources, especially to files uploaded, because there is no assurance the files will live in the future. Instead, reduce the log by filtering out unrelevant things (if you haven't already done so) and post the log directly here with markup. |
You are probably running out of sockets after a while. Try calling http.setReuse(true) before you call http.begin |
Same sketch is running flawlessly here. Failing request starts:
lots of https at the same time:
esp times out:
next requests are honored:
Be nicer with your server, increase ESP timeout. |
I've looked into the code and it seems it does keep the connection open. |
The default is 5. It can be increased up to 15 using espconn_tcp_set_max_con() from the ESP SDK. |
It doesn't. Variable scope implies the destructor is called and the connection closed at every loop (on
We don't depend on that. It's for |
My bad. Since everything is indeed cleared at every loop I would also suspect that the server is too slow. |
I meant the code of HTTPClient. |
This was reported for 2.5.2. There have been several critical stability fixes merged since then. Please retest with 2.6.3 or latest git. |
Closing as last update was Jun 18, there have been many HTTPClient updates, and there's been no response to @devyte's request for a confirmation this is still an issue in 2.7+ for ~4 months. If it does still show up in latest master, please open a new bug with MCVE/etc. so we can look at it. |
@earlephilhower , @devyte The issue with -1 still persists, went today from 2.3.0 to 2.7.1, but it's got worse, now I have delay, freezing issues too. This function is called every 10 seconds:
|
@beicnet, Can you please open a new issue with MCVE (and public file maybe on your GH acct or something so we can run it in our own environments) and also enable full debugging to get more useful logs? This is a closed issue from a long time ago, so it won't get attention otherwise. |
Hey @earlephilhower thank you for your fast response! ;) MCVE? Huh, there are 12 library included in my project, and also there are a lot of modules attached to the WeMos D1 mini board. Can you tell me which one is the full debug in Tools > Debug level? I'm still using Arduino 1.8.2 with 2.3.0 and everything was fine except that HTTP random response -1, and -2 code (as we speak I got -11 too). |
If you're using 2.3.0 then first move to 2.7.1 before trying anything else. 2.3.0 is ancient. For debug, just select the longest one (2nd from last in the menu, it's got about 12 things listed. If it still has issues w/the latest version, then you'll have to strip it down to a simple example. If it's just the http stuff, you should be able to reproduce the failure with just a loop() that calls your update stuff. If you can't strip things down, again there's not much we can do, but you can use https://esp8266.com forums for more help. |
Yes, @earlephilhower I moved directly to 2.7.1. Could not use 2nd from last in the menu, because I got BSSL error at compiling and I used 3th from the last in the menu. I managed to strip down the whole code, and it's just the http stuff in the loop. Stripped code and Debug information follows:
Debug information:
|
Looks like it's fine, no -1 response shown. You should look to capture a -1 code... |
@earlephilhower There is a 3 second total freeze between the ARROW shown:
|
That's not an error. You'd need to go over the server it's connecting to and what it's transmitting (wireshark). As a guess I would say that the HTTP server is doing something funky here and not identifying the content size properly so the client waits a couple seconds until timeout and return of the string. Wireshark on the network to capture both sides of the transaction is your best bet to debugging this. That said, it seems like this is really something you're going to have to go to esp8266.com or https://gitter.im/esp8266/Arduino to track down since it's not really a core thing so far. |
Ok, just installed Wireshark, any suggestion for the filter and what should I look for? (first time with Wireshark) @earlephilhower |
Just one thing to test first before experimenting with filter. |
Hey @TD-er I managed to filter traffic for 8008 port, the Source device (client) is 192.168.0.25 and the destination device (server) is 192.168.0.132 |
The reason I mentioned it was that it is also possible the network packets do not reach the host you're running Wireshark on. But if you can see the packets using Wireshark, then you know you can trust the setup and start filtering. |
I don't know @TD-er , I'm new to Wireshark, no time to learn it, but what can I say, I went back to core 2.3.0 and it's working without any issues for now again. What I noticed so far are those time latency and freezing with 2.7.1:
Used the same stripped sketch posted above. |
Just one thought. I can imagine that trying to get the resulting string may wait until the transfer is considered complete. Maybe it would help to also include the |
@beicnet why didn't you open a new issue ? It's not 3 second but 5 second according to wireshark log (which is the default timeout in http client). |
Sorry about that @d-a-v , I'm totally lost because of my job. Requested CURL output:
ASP page source follows:
and it's happening randomly using core 2.3.0
Using latest core 2.7.1, it's freezes the whole sketch. |
From what I can see it's not a chunked answer so you must have a |
Edited the source ASP page @d-a-v
Result:
|
The It means the client write of the headers did not write the full amount of headers to the server. See So, if Wifi goes down and isn't reconnected, that's one possibility. If the server sends a TCP disconnect (maybe it's rate-limiting or maybe it's slow), that's another possibility. If the WiFi signal isn't strong enough and the TCP ACK is lost, that's another option. @d-a-v, can client->write fragment and only write a lesser portion of the data? If so, then the code here needs to be reworked to attempt multiple writes as long as the written bytes != 0...
|
@earlephilhower , @d-a-v I have some weird guessing here, is it possible that in the WeMos D1 mini devices the AT firmwares are not the same? Because I bought 150pcs of them what I currently testing, but I have one device running with the same code and it's rarely giving me response error code (maybe 1 time from 10000 loops) against these new one (like 15 times from 50 loops)?! Is it possible or? I don't know nothing anymore, struggling with this like more than 10 days...
|
Try to set This way you know for sure it cannot be impacted by some modules needing more time to connect. |
Regarding my device RSSI is -76 @earlephilhower @TD-er Did it as per your suggestion, but I got the same result right from the beginning:
Results:
|
@beicnet there is no different hardware. @earlephilhower Maybe we should add the result in the debug messages ? size_t ret = _client->write((const uint8_t*)header.c_str(), header.length();
DEBUGV(..., header.length(), ret);
return ret == header.length()); |
Yes > Can you enable the debug options ? and let's wait a little bit for the output to populate a few cycle of loop... |
|
@earlephilhower @d-a-v Any news?! |
It seems that your webserver is not responding to incoming connections sometimes. Also, error -11 = http read timeout following
What are the values ? Did you try to use |
@d-a-v Could it be the 10s request time period? (there will be 150 devices with same request). What values? But I have another theory here... |
HTTPClient is blocking during at most the timeout.
My theory:
|
@d-a-v Nah, I think the NFC module is jamming the ESP module... |
My theory is still good, try to change your |
Yes, @d-a-v I changed the suggested "if", but it's the same.
If I comment out the rfid function from the loop then there is no issues whatsoever. Yes, the chip is shielded! |
@TD-er Can you please verify for me something? |
@beicnet What do you want me to verify? |
@TD-er Do you have a PN532 module by your side? |
Not sure, have to dig in the drawer(s) of sensors. |
@TD-er I think there is an incompatibility in Adafruits PN532 and HTTPClient library, but I'm not quite sure, because there is no other person to confirm it, that's why I asked you for the module and to test it in SPI mode. I can give you the MCVE to test it if you would willing to do it for me. You need WeMos D1 mini, PN532 module and a 6-pin Dupont cable. |
I've gone over this and what I get as the end result is that with a specific NFC sensor placed next to the 8266 is enabled, WiFi has issues which are reflected in HTTPClient returning (correctly) failure occasionally. I'm not seeing any core issue here, more of a RF or power supply one. Given that, this is not the right place for a HW discussion like this, so I suggest moving to https://esp8266.com or https://gitter.im/esp8266/Arduino . Closing. |
@earlephilhower If you put the NFC reader to 10cm dupont cable, you got the same results. |
@earlephilhower @d-a-v I also tried across 20cm Dupont cable and the results are the same. So, I don't think it's a hardware nor power supply issue. I think it's library incompatibility (some sort of timing) issue. You can read my full description on the forum. |
To summarize: when library is not used, httpclient works.
Can you enable terminal timestamp and show an error with all debug options enabled ?
|
@d-a-v Thank you for replying, your summation is 99% correct. with Function Enabled:
with Function Disabled:
Also I tried to implement the |
With console timestamps + wireshark, or with one of the two netdumps, as described above, we will be able to check if packets are arriving onto the esp during the http timeout. |
@d-a-v I accidentally found out the solution,... I put my hand onto PN532 module and it's started to give correct reading/requests. And it's no matter how long cable you will put on the PN532 module (10cm or 20cm) or distance you put the module from ESP device. Even after I taped Copper foil on the back of the PN532 module wouldn't do nothing. @earlephilhower was almost right about one thing, but it was not the RF signal interference, it was the EMI impulses so hard that it was killing the whole ESP device. So, I made an ESD cage for the PN532 module from Aluminium and Copper adhesive tape over Plexiglas stand. Sorry for bother you, now we know a little bit more about red PN532 module and how can be used properly. |
Thanks for the follow up, @beicnet ! You may want to post something about this on the Adafruit library github so they can put it in their |
@earlephilhower I already did that before 6 days ago, nobody replayed (nor interested), so I closed the issue yesterday on the Adafruits GIT page. Anyway I got immediate response and better support here! 🥇 😉 |
Basic Infos
Platform
Settings in IDE
Problem Description
Hello, I have the following problem:
I am using a esp8266, via an httpclient to connect to a server, but after some time (random), it returns me the following error:
httpCode: -1 (Connection Refused). With wireshark I noticed that it [TCP PORT numbers reused] 57490-> 8000 [SYN].
I would like to know what I am doing wrong in my code to receive this error.
[Sketch]
Debug Messages
16:33:26.338 -> 192.168.0.192
16:33:34.254 -> pm open,type:2 0
16:33:37.970 -> httpCode:-1
wireshark report :
https://mega.nz/#!jJ4wRIyQ!6ayDTjoxEgaxO82yBo-0I4PwqH33TpPVC9XijBe2EXg
The text was updated successfully, but these errors were encountered: