FTP error... but only at certain times, and in only one location

Hey guys,
I have a strange question for you. I'm using a program that:

  • collect data from a sensor
  • save it locally with SPIFFS
  • connect to WiFi
  • send data to a server via ftp protocol

This program was done 1 year ago and it's working fine in tens of different locations with different WiFi boxes (house, buildings...). In only one building, it behaves strangely. In this building, I have 2 sensors (in 2 different appartments, connected to the same WiFi) that suddenly doesn't work while they were working fine for 3 months. I changed the WiFi, same problem. I changed the PCB, same thing. The problem happens while sending data via ftp:
I have this:

Connecting Wifi....
WiFi connected -> IP address: 192.168.1.113
Connecting to: XXX (it's not XXX of course!)
Command connected
Send USER
Send PASSWORD
Send SYST
Date : 2024-11-27 16:25:20
Starting FTP-Upload...
Send TYPE
Type A
Send PASV
Data port: 40175
Send CWD
Send STOR
FTP error: Offline
SPIFFS fileD OK
Write File
FTP error: Offline
Close File
Connection closed
Data sent...

For info, this is my WiFi function

void wifiSetup() {
  WiFi.mode(WIFI_STA);
  WiFi.begin( WIFI_SSID, WIFI_PASS );

  wifiAttempt = 0;
  Serial.print((String)"Connecting Wifi...");
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    wifiAttempt++;
    Serial.print(".");
    if (wifiAttempt > 20)
      break;
  }

  if (WiFi.status() != WL_CONNECTED) {
    Serial.println(F("\nCould not connect after 10sec... "));
  }
  else {
    Serial.print(F("\nWiFi connected -> IP address: "));
    Serial.println(WiFi.localIP());    
  }
  yield();
}

And the way how I sent data via ftp:

  if (WiFi.status() == WL_CONNECTED) {

    ftp.OpenConnection();

    if (ftp.isConnected()) {
      timeStamp = getTheTime();

      ftpFileSM.toCharArray(ftpFileSM_char, str_len);

      // Create the file new and write a string into it
      Serial.println(F("Starting FTP-Upload...")); 
      ftp.InitFile("Type A");
      //String list[128];
      ftp.ChangeWorkDir(ftpPath);

      ftp.NewFile(ftpFileSM_char);
      String dataToSend = "";
      dataToSend += (String)noWifiCounter + "\n";
      dataToSend += timeStamp + "\n";
   
      dataToSend += valueA + "\n";
      dataToSend += valueB + "\n";
      dataToSend += valueC;
      ftp.Write(dataToSend.c_str());
      ftp.CloseFile();
      
      ftp.CloseConnection();

      Serial.println(F("Data sent..."));

    }
}

Any idea how such an error can suddenly happens?
Thanks for your suggestions.
Laurent

What do you mean by "only position"? Are you referring to the location of the module or its physical rotation?

Could the issue be related to the lease on the IP address expiring, or is there another system coming online using the same IP? Is the module located near a microwave or other device that could cause interference? Could the router itself be the problem, perhaps due to too many connections?

Since I can’t see your system, I’m trying to understand what you have in place. Intermittent issues like this can be particularly challenging to diagnose, but with more details, we can narrow it down. Let me know!

Sorry, the word "position" was not appropriate, I meant "location". I have about 150 of these sensors in about 50 different locations in my country and it's the only building that causes me this problem.

Does this happens after a certain time? If so, I don't think this is the problem because it happened either after I switched to a new box at the beginning, or after 3 months of use.

It could be but I would be very unlucky because I have 2 sensors and they both started showing this problem at the same time. It was 2am when it happened last time.

They are both located on the balcony, outside and far from any other devices.

It could be. But again, the last router I used was used by 2 persons and nothing was on when I was there.

Thanks for trying. It doesn't make sense at all to me. There's a reason for everything, but this one is pretty well hidden!

I would check the availability of the FTP resource using PUTTY

Could it be that this building, or one close by has got antenna on the roof and some update to what these do has changed and is now causing interference to your system?

That's not all your code, but I'll try to help.
Maybe it's timing out before it receives anything. I don't know where you got the library, but by the responses, I presume here:

Edit: millis() rolls over to zero about every 49 days. Just a thought.

void FTPClient_Generic::GetFTPAnswer (char* result, int offsetStart)
{
  char thisByte;
  outCount = 0;

  unsigned long _m = millis();

  while (!client.available() && millis() < _m + timeout)
    delay(100);

  if ( !client.available())
  {
    memset( outBuf, 0, sizeof(outBuf) );
    strcpy( outBuf, "Offline");

    _isConnected = false;
    isConnected();

    return;
  }

while (!client.available() && millis() - _m <= timeout)

Good point, I will check next time I go there.

Will check that too

I'm using actually the library ESP32_FTPClient ( ESP32_FTPClient/ESP32_FTPClient.h at master · blackcodetavern/ESP32_FTPClient · GitHub)

It's basically the same. This indicates a timeout.
FTP error: Offline
Here is the function:

void ESP32_FTPClient::GetFTPAnswer (char* result, int offsetStart) {
  char thisByte;
  outCount = 0;

  unsigned long _m = millis();
  while (!client.available() && millis() < _m + timeout) delay(1);

  if( !client.available()){
    memset( outBuf, 0, sizeof(outBuf) );
    strcpy( outBuf, "Offline");

    _isConnected = false;
    isConnected();
    return;
  }
1 Like

Oh I see, so I can increase this time and see what happens...

// you can pass a FTP timeout and debbug mode on the last 2 arguments
ESP32_FTPClient ftp (ftp_server,ftp_user,ftp_pass, 5000, 2);

Thanks!

If that timeout value is what you used before, then increase it to 10000
The default timeout is 10 seconds (10000).

Great, I will let you know.