Wifi problems (can connect, but it is unreliable)

Radu79
Posts: 29
Joined: Tue Nov 17, 2020 9:50 pm

Wifi problems (can connect, but it is unreliable)

Postby Radu79 » 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:

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;

}
If you have any ideas, I'd be really thankful.

Radu79
Posts: 29
Joined: Tue Nov 17, 2020 9:50 pm

Re: Wifi problems (can connect, but it is unreliable)

Postby Radu79 » Wed Nov 18, 2020 4:18 pm

So, I tried again the webserver example (the one where you stream the camera), which worked fine.
After that, I tried my code again and now it works just fine...

Any ideas?

Radu79
Posts: 29
Joined: Tue Nov 17, 2020 9:50 pm

Re: Wifi problems (can connect, but it is unreliable)

Postby Radu79 » Wed Nov 18, 2020 9:00 pm

That did work for a while, then stopped working again.

I tried other things, some suggested by others for a slightly different problem, and now it works pretty ok.
Here is the solution (that worked for me)

Code: Select all

  WiFi.begin ( ssid, pass );
  delay(1000);
  WiFi.disconnect();
  delay(400);
  WiFi.begin ( ssid, pass );
So clearly, this is a software bug, that has been around for years. Is there any reason why this isn't investigated more by the developers?

Radu79
Posts: 29
Joined: Tue Nov 17, 2020 9:50 pm

Re: Wifi problems (can connect, but it is unreliable)

Postby Radu79 » Thu Nov 19, 2020 11:29 am

And now even this solution stopped working...
Btw, with the provided Web camera example, the first time I connect to the server it doesn't work. It just waits for a reply indefinitely. However, if I go to that URL again the second time, it works fine.

alanesq
Posts: 84
Joined: Thu Dec 14, 2017 8:38 pm

Re: Wifi problems (can connect, but it is unreliable)

Postby alanesq » Thu Nov 19, 2020 11:45 am

I would check the power to the esp32cam is good, maybe try it on another power supply with short, thick wires (ideally with a smoothing capacitor) as I have experienced no end of problems like this only to discover it is just a power problem.

BTW - I use FTP on an esp32cam module in this sketch https://github.com/alanesq/CameraWifiMotion
using this library: https://github.com/ldab/ESP32_FTPClient

Radu79
Posts: 29
Joined: Tue Nov 17, 2020 9:50 pm

Re: Wifi problems (can connect, but it is unreliable)

Postby Radu79 » Thu Nov 19, 2020 3:08 pm

I don't think it's a power problem, because the web server sample works fine (aside for the problem with having to connect twice).
I also connected it to a 3.2v battery, and it didn't work either.

I tried a sample using the same library too, btw. Very simple code, just sends user, password, and tries to upload that cat picture. It fails...

What I am trying to do is writing a program that randomly modifies registries for the ov2640 sensor and saves the pictures, so I can document some undocumented registers. I've been doing that manually for a while, but it is getting tedious, and automating it is better. I was hoping to upload the images on my local ftp server and see the results in real time, but I am giving up, because it's just not worth it. I will just save the pictures on the SD card for now....

Radu79
Posts: 29
Joined: Tue Nov 17, 2020 9:50 pm

Re: Wifi problems (can connect, but it is unreliable)

Postby Radu79 » Thu Nov 19, 2020 3:21 pm

To completely rule out any power issues, I connected it to my bench power supply, at 5.2v. Still no uploads from the simple, 'failproof' ftp sample.

Spile2
Posts: 23
Joined: Tue Sep 22, 2020 8:39 pm

Re: Wifi problems (can connect, but it is unreliable)

Postby Spile2 » Thu Nov 19, 2020 9:54 pm

I did notice different WiFi performance between two boards from different manufacturers. The removal of the white paint as described below did actually make a difference...
https://www.hackster.io/rayburne/esp32- ... one-7f4ff7

Radu79
Posts: 29
Joined: Tue Nov 17, 2020 9:50 pm

Re: Wifi problems (can connect, but it is unreliable)

Postby Radu79 » Thu Nov 19, 2020 10:07 pm

The thing is, I print the wifi signal strength at a few times in my code. The connection is good, -50 or -60 db at most. And not even the ftp handshake gets through...

jamesmknox
Posts: 1
Joined: Wed Nov 25, 2020 7:49 pm

Re: Wifi problems (can connect, but it is unreliable)

Postby jamesmknox » Wed Nov 25, 2020 7:58 pm

I have the same problem - sounds like. I bought a couple of the AI-Thinker ESP-32 CAM boards. I loaded the AI-Thinker CameraWebServer software without problems. Now both boards do what yours do. Namely, they run for a while and stop. Takes a hard reset to get them back online. I have tried both internal and external antenna, and even running them in the server room - so signal strength is no problem.

They connect to the network (usually) and can be ping'd or opened from a web browser. They will then work fine for anywhere from a couple of seconds to 10 minutes, seemingly random. Good 5V power, plenty of current. Frankly, it feels like a software issue, but I have not tackled the debugging yet. For now I just wanted to hook them up and run - add features later.

Yes, I apologize in advance. I know this isn't much information to go on - UNLESS it's a known problem. Something like a pullup resistor that needs to be added to a signal, or a known software correction. Suggestions appreciated.

Who is online

Users browsing this forum: No registered users and 61 guests