Problems sending data by FTP

Post Reply
lpzb
Posts: 7
Joined: Tue Dec 17, 2019 10:49 am
Company: Tragsatec

Problems sending data by FTP

Post by lpzb » Tue Dec 17, 2019 4:43 pm

I get in touch with you because I am having trouble sending a file via FTP through your P&S module model 4-20 mA 4G EU / BR serial number 582BBC32C8913E33 with 4G radio. I am using a SIM card with a disabled PIN. The FTP server I want to connect to is behind a Proxy or NAT device.
When I try to connect, the following messages appear:
• 16: if an error occurs when opening the FTP connection.
• 3: registration denied.

It is possible to connect and send files to the FTP server using the FileZilla application, using the same username and password that appears in the P&S code.

I am using the following code without compilation errors. The username and password are modified since I don't want it to appear in the thread, but I check it out and are the right ones.

Code: Select all

#include "Wasp4G.h"

char SD_FILE[]     = "WASP01.TXT";
char SERVER_FILE[] = "RutaAcceso/WASP01.TXT";

int answer;
int fileSize;

void setup()

{
  USB.ON();
  USB.println(F("Inicio programa"));
  SD.ON();
  USB.println(F("Size SD:"));
  USB.println(SD.diskSize);
  USB.println(F("File list:"));
  SD.ls(LS_R|LS_DATE|LS_SIZE);
  USB.println(F("****Making a file****"));
  answer = SD.isFile(SD_FILE);

  if (answer == 1){
    USB.printf("Is file: %d\n",answer);
  }else{
    USB.printf("Not a file: %d\n",answer);
    answer = SD.create(SD_FILE);
    USB.printf("Created: %d\n",answer);
  }

  fileSize = SD.getFileSize(SD_FILE);

  if (fileSize < 50){
    USB.println(F("****Writing file****"));
    answer = SD.append(SD_FILE, "2019-12-17;25.33;12.56");
  }else{
    USB.printf("File size: %d\n",fileSize);
  }
  
  _4G.set_APN("ac.vodafone.es","vodafone","vodafone");
  _4G.show_APN();

  answer == _4G.ON();
  USB.printf("_4G.ON %d\n",answer);

  answer = _4G.checkConnection(60); 
  USB.printf("_4G.checkConnection %d\n",answer);

  answer = _4G.checkDataConnection(60); 
  USB.printf("_4G.checkDataConnection %d\n",answer);

answer =   _4G.ftpOpenSession("FTP.YYYYYY.ES",21,"UUUU/Uuuu_Uuuu","clave");
  USB.printf("_4G.ftpOpenSession %d\n",answer);

  answer = _4G.ftpUpload(SD_FILE, SERVER_FILE);
  USB.printf("_4G.ftpUpload %d\n",answer);
  _4G.OFF();
}

void loop()
{
 
}
The program has the following output.

La salida del programa es la siguiente:
J#
Inicio programa
Size SD:
0
File list:
WASP01.TXT 2019-12-16 16:52:10 66
****Making a file****
Is file: 1
File size: 66
*****************************
APN: ac.vodafone.es
LOGIN: vodafone
PASSWORD: vodafone
*****************************
_4G.ON 1
_4G.checkConnection 0
_4G.checkDataConnection 0
_4G.ftpOpenSession 16
_4G.ftpUpload 3

libelium-dev
Posts: 27967
Joined: Mon Sep 28, 2009 1:06 pm

Re: Problems sending data by FTP

Post by libelium-dev » Wed Dec 18, 2019 1:46 pm

Hi,

Is the FTP active or passive? It is set to passive by default in the library, you can use the following funtion to configure active FTP

Code: Select all

answer =   _4G.ftpOpenSession("FTP.YYYYYY.ES",21,"UUUU/Uuuu_Uuuu","clave", Wasp4G::FTP_ACTIVE);
Also, please try to set debug mode 2 in the Wasp4G.h file and upload the FTP example code to the node with your settings
http://www.libelium.com/development/was ... tp-upload/

Regards

lpzb
Posts: 7
Joined: Tue Dec 17, 2019 10:49 am
Company: Tragsatec

Re: Problems sending data by FTP

Post by lpzb » Thu Dec 19, 2019 7:02 pm

Hello.

The FTP server works both ways (active and passive), since P&S is accessing to FTP server through a NAT device, I think the passive mode is the correct configuration. Is it right?

lpzb
Posts: 7
Joined: Tue Dec 17, 2019 10:49 am
Company: Tragsatec

Re: Problems sending data by FTP

Post by lpzb » Fri Dec 20, 2019 2:39 pm

I’ve tried the change in the _4G.ftpOpenSession function and activated the debug mode 2 in Wasp4G.h file, with the following results.



Inicio programa
Size SD:
0
File list:
WASP01.TXT 2019-12-16 16:52:10 66
****Making a file****
Is file: 1
File size: 66
*****************************
APN: ac.vodafone.es
LOGIN: vodafone
PASSWORD: vodafone
*****************************
[LE910] GPRS context activation:0
_4G.ON 1
[LE910] Break condition
[LE910] answer:1
_4G.checkConnection 0
[LE910] CREG: 0,1
[LE910] CGREG: 0,1
[LE910] GPRS context activation:1
[LE910] IP address:47.59.31.135
_4G.checkDataConnection 0
[LE910] Checking connection
[LE910] Connection active, nothing more to check
[LE910] Opening FTP session
[LE910] ==> ERROR CODE: UNKNOWN
[LE910] ==> ERROR CODE: UNKNOWN
_4G.ftpOpenSession 16

[LE910] _buffer:
+CME ERROR:
[LE910] Error deleting file
[LE910] ==> ERROR CODE: FTP not connected
[LE910] ==> ERROR CODE: FTP not connected
[LE910] Error: opening file
_4G.ftpUpload 3



Moreover I tested your example code with this output result.


[LE910] GPRS context activation:0
1. 4G module ready...
[LE910] Checking connection
[LE910] CREG: 0,1
[LE910] CGREG: 0,1
[LE910] GPRS context activation:1
[LE910] IP address:62.174.24.232
[LE910] Opening FTP session
[LE910] ==> ERROR CODE: UNKNOWN
[LE910] ==> ERROR CODE: UNKNOWN
2.1. FTP connection error: 16

3. Switch OFF 4G module
4. Enter deep sleep...
5. Wake up!!

libelium-dev
Posts: 27967
Joined: Mon Sep 28, 2009 1:06 pm

Re: Problems sending data by FTP

Post by libelium-dev » Tue Dec 24, 2019 12:53 pm

Hi,

Please try the following example code which uses our FTP test server. Just configure your APN settings. Does it work?

Code: Select all

#include <Wasp4G.h>

// APN settings
///////////////////////////////////////
char apn[] = "movistar.es";
char login[] = "movistar";
char password[] = "movistar";
///////////////////////////////////////

// SERVER settings
///////////////////////////////////////
char ftp_server[] = "pruebas.libelium.com";
uint16_t ftp_port = 21;
char ftp_user[] = "usertech03";
char ftp_pass[] = "jHYSD765rFADS";
///////////////////////////////////////

///////////////////////////////////////////////////////////////////////
// Define filenames for SD card and FTP server:
//  - If the file is in the root directory: "FILE.TXT" or "/FILE.TXT"
//  - If the file is inside a folder: "/FOLDER/FILE.TXT"
///////////////////////////////////////////////////////////////////////
char SD_FILE[]     = "FILE1.TXT";
char SERVER_FILE[] = "FILE2.TXT";
///////////////////////////////////////////////////////////////////////

// define variables
int error;
uint32_t previous;
uint8_t sd_answer;

void setup()
{
  USB.ON();
  USB.println(F("Start program"));

  //////////////////////////////////////////////////
  // 1. sets operator parameters
  //////////////////////////////////////////////////
  _4G.set_APN(apn, login, password);


  //////////////////////////////////////////////////
  // 2. Show APN settings via USB port
  //////////////////////////////////////////////////
  _4G.show_APN();


  //////////////////////////////////////////////////
  // 1. Create a new file to upload
  //////////////////////////////////////////////////

  ///////////////////////////////////
  // 1.1. Init SD card
  ///////////////////////////////////
  sd_answer = SD.ON();

  if (sd_answer == 1)
  {
    USB.println(F("1. SD init OK"));
  }
  else
  {
    USB.println(F("1. SD init ERROR"));
  }

  ///////////////////////////////////
  // 1.2. Delete file if exists
  ///////////////////////////////////
  sd_answer = SD.del(SD_FILE);

  if (sd_answer == 1)
  {
    USB.println(F("2. File deleted"));
  }
  else
  {
    USB.println(F("2. File NOT deleted"));
  }

  ///////////////////////////////////
  // 1.3. Create file
  ///////////////////////////////////
  sd_answer = SD.create(SD_FILE);

  if (sd_answer == 1)
  {
    USB.println(F("3. File created"));
  }
  else
  {
    USB.println(F("3. File NOT created"));
  }

  ///////////////////////////////////
  // 1.4. Append contents
  ///////////////////////////////////
  USB.println(F("4. Appending data..."));
  for (int i = 0; i < 90; i++)
  {
    sd_answer = SD.append( SD_FILE, "This is a new message\nThis is a new message\nThis is a new message\nThis is a new message\nThis is a new message\n");

    if (sd_answer != 1)
    {
      USB.println(F("SD append error"));
    }
    else
    {
      USB.println(F("SD append ok"));
    }
  }

  ///////////////////////////////////
  // 1.5. Close SD
  ///////////////////////////////////
  SD.OFF();
  USB.println(F("5. SD off"));
  USB.println(F("Setup done\n\n"));
}



void loop()
{
  //////////////////////////////////////////////////
  // 1. Switch ON
  //////////////////////////////////////////////////
  error = _4G.ON();

  if (error == 0)
  {
    USB.println(F("1. 4G module ready..."));

    ////////////////////////////////////////////////
    // 2.1. FTP open session
    ////////////////////////////////////////////////

    error = _4G.ftpOpenSession(ftp_server, ftp_port, ftp_user, ftp_pass, 0);

    // check answer
    if (error == 0)
    {
      USB.println(F("2.1. FTP open session OK"));

      previous = millis();

      //////////////////////////////////////////////
      // 2.2. FTP upload
      //////////////////////////////////////////////

      error = _4G.ftpUpload(SERVER_FILE, SD_FILE);

      if (error == 0)
      {

        USB.print(F("2.2. Uploading SD file to FTP server done! "));
        USB.print(F("Upload time: "));
        USB.print((millis() - previous) / 1000, DEC);
        USB.println(F(" s"));
      }
      else
      {
        USB.print(F("2.2. Error calling 'ftpUpload' function. Error: "));
        USB.println(error, DEC);
      }


      //////////////////////////////////////////////
      // 2.3. FTP close session
      //////////////////////////////////////////////

      error = _4G.ftpCloseSession();

      if (error == 0)
      {
        USB.println(F("2.3. FTP close session OK"));
      }
      else
      {
        USB.print(F("2.3. Error calling 'ftpCloseSession' function. error: "));
        USB.println(error, DEC);
        USB.print(F("CMEE error: "));
        USB.println(_4G._errorCode, DEC);
      }
    }
    else
    {
      USB.print(F( "2.1. FTP connection error: "));
      USB.println(error, DEC);
    }
  }
  else
  {
    // Problem with the communication with the 4G module
    USB.println(F("1. 4G module not started"));
  }


  ////////////////////////////////////////////////
  // 3. Powers off the 4G module
  ////////////////////////////////////////////////
  USB.println(F("3. Switch OFF 4G module"));
  _4G.OFF();


  ////////////////////////////////////////////////
  // 4. Sleep
  ////////////////////////////////////////////////
  USB.println(F("4. Enter deep sleep..."));
  PWR.deepSleep("00:00:00:10", RTC_OFFSET, RTC_ALM1_MODE1, ALL_OFF);

  USB.ON();
  USB.println(F("5. Wake up!!\n\n"));

}
Regards

lpzb
Posts: 7
Joined: Tue Dec 17, 2019 10:49 am
Company: Tragsatec

Re: Problems sending data by FTP

Post by lpzb » Thu Dec 26, 2019 4:54 pm

Hello.
I checked it, at the end,the problem relies on the way your 4G and 3G libraries deal whith the strings like ZZZZ\xxxxxxxx. In my case this string identifies the FTP user. In order to avoid error 16 when the program opens the FTP session, it must be entered in the program in this way:

ZZZZ\\xxxxxxxx

Besides, it’s important to use the _4G.ftpChangeWorkingDirectory function to access the right FTP folder.

Thank you.

libelium-dev
Posts: 27967
Joined: Mon Sep 28, 2009 1:06 pm

Re: Problems sending data by FTP

Post by libelium-dev » Fri Dec 27, 2019 8:59 am

Hi,

Glad to hear that you solved the issue! :)

Regards

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest