Wifi problems (can connect, but it is unreliable)
Posted: Tue Nov 17, 2020 9:59 pm
I'm using an ESP32-cam board.
I can connect to the wifi quite well, the signal is good (it's right next to the router).
I'm trying some simple FTP upload code that I used a while ago on an esp8266. It worked fine on the esp8266, but not on the ESP32. I also tried a FTP library, and the result is the same.
I have two boards, and the problem is the same on both, so not a bad board.
From searching online, most people had trouble connecting to a network. I don't have that problem, my problem is actually getting/sending data. Sometimes it will connect to the server, and I get a reply. Sometimes it even goes as far as sending the user and getting a reply. Most of the times it doesn't even reach getting a reply after the password.
Here is the relevant code:
If you have any ideas, I'd be really thankful.
I can connect to the wifi quite well, the signal is good (it's right next to the router).
I'm trying some simple FTP upload code that I used a while ago on an esp8266. It worked fine on the esp8266, but not on the ESP32. I also tried a FTP library, and the result is the same.
I have two boards, and the problem is the same on both, so not a bad board.
From searching online, most people had trouble connecting to a network. I don't have that problem, my problem is actually getting/sending data. Sometimes it will connect to the server, and I get a reply. Sometimes it even goes as far as sending the user and getting a reply. Most of the times it doesn't even reach getting a reply after the password.
Here is the relevant code:
Code: Select all
//-------------- FTP receive
byte eRcv() {
byte respCode;
byte thisByte;
if (debug) Serial.println(F("Started eRcv")); //!!!!!!!!!!!USUALLY HANGS HERE!!!!
while (!client.available()) delay(1);
respCode = client.peek();
outCount = 0;
while (client.available()) {
thisByte = client.read();
Serial.write(thisByte);
if (outCount < 127) {
outBuf[outCount] = thisByte;
outCount++;
outBuf[outCount] = 0;
}
}
if (debug) Serial.println(F("Leaving eRcv"));
if (respCode >= '4') {
efail();
return 0;
}
return 1;
} // eRcv()
byte setup_ftp()
{
client.setNoDelay(1);
if (debug) Serial.println(F("SPIFFS opened"));
//delay(1000);
if (client.connect(server, 21)) { // 21 = FTP server
Serial.println(F("Command connected"));
} else {
Serial.println(F("Command connection failed"));
return 0;
}
if (!eRcv()) return 0;
if (debug) Serial.println("Send USER");
//client.println(F("USER upload"));
client.println(F("USER test"));
if (!eRcv()) return 0;
if (debug) Serial.println("Send PASSWORD");
client.println(F("PASS test"));
/*
if (!eRcv()) return 0;
if (debug) Serial.println("Send SYST");
client.println(F("SYST"));
*/
if (!eRcv()) return 0;
if (debug) Serial.println("Send Type I");
client.println(F("Type I"));
if (!eRcv()) return 0;
}