-
Notifications
You must be signed in to change notification settings - Fork 7.6k
why does Esp32 client.read() often return -1 while there is still data to be read? #4390
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
Comments
the Serial output isdownload file
|
I just ran into this. The problem is in "arduino-esp32/libraries/WiFi/src/WiFiClient.cpp". If the client has run out of data that has been received, it will return an error, instead of returning 0 (indicating no data available right now). Starting line 106:
Change to:
I'll report this as a specific issue, but I believe this is the root of your problem. |
Oh, and as a workaround - try changing from |
Hi, @MHotchin thank you for your help. I changed WiFiClient.cpp line 108 from "return -1;" to “return _failed ? -1: 0;” then the program stuck in the while loop. When I changed read() to readBytes(), it also stuck in the while loop, no matter whether I modified WiFiClient.cpp or kept it original version. Thanks again.
|
With this fix, if you do get -1 (or any negative value) as a return val, that's an actual error - you're done. So, I think you need to Also, if you get zero bytes, you may need to delay() to allow other ESP32 code to run, otherwise the loop will hog the processor. Not sure if that's relevant to your problem here, though.
|
@MHotchin If this is a solid fix, can you submit it as a PR? |
@MHotchin Thanks you. Thanks again.
|
[STALE_SET] This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs. Thank you for your contributions. |
[STALE_DEL] This stale issue has been automatically closed. Thank you for your contributions. |
Hardware:
Board: ESP32 Dev Module(ESP32-WROOM-32)
Core Installation/update date:
IDE name: Arduino IDE 1.8.13
Flash Frequency: 80Mhz
PSRAM enabled: Disabled
Upload Speed: 921600
Computer OS: Windows 10
Description:
I am trying to test WiFi data transfer between cell phone and Esp32, the routine is:
1, filename
2, file size
3, file data
when ESP32 reads files via WiFi, even there is still data in, client.read() often return -1, I have to add other conditions to check reading finished or not.
My questions is why there are so many failed read, any ideas are highly appreciated.
Sketch: (leave the backquotes for [code formatting](https://help.github.com/articles/creating-and-highlighting-code-
#include <SPI.h>
#include <WiFi.h>
#include <WiFiClient.h>
#include <WiFiAP.h>
#define
// Set these to your desired credentials.
const char* ssid = "TestAP";
const char* password = "12345678";
WiFiServer server(6666);
int i,j;
char toClient[128]={0};
byte cmd;
unsigned long pretime=0;
unsigned long curtime=0;
void setup()
{
i=0;
Serial.begin(115200);
Serial.println("begin...");
}
// the loop function runs over and over again until power down or reset
void loop()
{
}
The text was updated successfully, but these errors were encountered: