Page 1 of 1

P&S 3G v12 - OTA error code -21 with external FTP

Posted: Fri Sep 28, 2018 10:18 am
by smontoya
Hi libelium,
A couple of problems with my new P&S SC 3G v12.

1. RTC.setTime is not doing its function, I set the time with format 18:09:28:06:10:07:32 from my URL, but when I get the time later in the code, time wasn't set.

2. OTA error code -21 with extern FTP server. Any reminder about format of the UPGRADE or filecode?
binary to be download: prog001.pde.hex
UPGRADE.txt:

Code: Select all

FILE:prog001
PATH:/ota/ruido
SIZE:52713
VERSION:15

Code: Select all

/*
 *  -------- Waspmote ------------- 
 *  Conexión :          WASPMOTE 3G
 *  PIN :               
 *  Nº Serie :          
 *  Nombre Nodo:        
 *  Canal :             
 *  Modelo  :           Smart Cities
 *  Slot A:             --  
 *  Slot B:             --
 *  Slot C:             --
 *  Slot D:             AUDIO
 *  Slot E:             --
 *  Slot F:             --
  * ---------------------------------------
 *  Cliente :           
 *  Version :           
 *  Generado:		 17/09/2018
 * ---------------------------------------
*/  
// Step 1. Includes of the Sensor Board and Communications modules used
#include <WaspSensorCities.h>
#include <Wasp3G.h>

// Step 2. Variables declaration
char  nodeID[10];     
char data[100];

char* sleepTime = "00:00:03:00"; 

long  sequenceNumber = 0; 

float value_ruido;
char  t_value_ruido[15];  
char  txt_MCP[4]="MCP";

int   batteryLevel;
char  batteryLevelString[10];
char  BATTERY[4] = "BAT";

char  TIME_STAMP[3] = "TS";

#define URL "http://data.com/data?"
#define URLHora "http://data.com/hora"
int port = 80;
char request[] = "request";

char body[150];
unsigned long iNumSerie = 0;
char NumSerie[20];
char APN_Operador[]="xxxx";
char APN_Usuario[]="xx";
char APN_Password[]="xx";
char pin_code[5] = "xxx";
int answer;

int answerota, counter;
char ftp_address[]="ftp";
char ftp_port[]="21";
char ftp_user_name[]="user";
char ftp_password[]="pass";


void setup() {   
// Step 1. OTA
    //Check if the program has been programmed succesfully
    answerota = Utils.checkNewProgram();
    switch (answerota)
    {
      case 0:
        USB.println(F("REPROGRAMMING ERROR"));
        break;
      case  1:
        USB.println(F("REPROGRAMMING OK"));
        break;
      default:
        USB.println(F("RESTARTING"));
    }
    USB.print(F("Program version: "));
    USB.println(Utils.getProgramVersion(), DEC);

// Step 3. Communication module initialization
// Step 4. Communication module to ON

    // Activate the GPRS modules
    // Turn on the RTC
    RTC.ON();
    RTC.clearAlarmFlag();
    
    // Coger el Número de serie del dispositivo.
    iNumSerie = Utils.readSerialID();
    Utils.long2array(iNumSerie, NumSerie); 
    sprintf(data, "Modulo Waspmote con ID => %s iniciado.", NumSerie);
    USB.println(data);

    // Fijamos la hora con el servidor  
    FijaHora();

    // Cerramos.
    USB.OFF();
    delay(100);
    
}


void loop() {
//*****************************************************************
//    User loop program
//*****************************************************************
// put your main code here, to run repeatedly:

// Step 8. Turn on the Sensor Board
    // Encender el RTC
    RTC.ON();
    
    // Encendemos la placa
    SensorCities.ON();
    
    // Mostramos la carga de la batería...
    USB.print(F("Battery Level: "));
    USB.print(PWR.getBatteryLevel(),DEC);
    USB.print(F(" %"));
        // Show the battery Volts
    USB.print(F(" | Battery (Volts): "));
    USB.print(PWR.getBatteryVolts());
    USB.println(F(" V"));    

// Step 9. Turn on the sensors

    // Encender, y esperar 5 seg a que se estabilice....
    SensorCities.setSensorMode(SENS_ON, SENS_CITIES_AUDIO);
    //SensorCities.setSensorMode(SENS_ON, SENS_CITIES_ULTRASOUND_5V);
    delay(5000);

// Step 10. Read the sensors
    // Leemos el sensor
    value_ruido = SensorCities.readValue(SENS_CITIES_AUDIO);
    // Convertimos los Floats a string para su envío.
    Utils.float2String(value_ruido, t_value_ruido, 2);

    //First dummy reading for analog-to-digital converter channel selection
    //SensorCities.readValue(SENS_CITIES_ULTRASOUND_5V, SENS_US_WRA1);
    //Sensor temperature reading
    //connectorBFloatValue = SensorCities.readValue(SENS_CITIES_ULTRASOUND_5V, SENS_US_WRA1);
    //Conversion into a string
    //Utils.float2String(connectorBFloatValue, connectorBString, 2);
  
    // Apagar el sensor
    SensorCities.setSensorMode(SENS_OFF, SENS_CITIES_AUDIO);
    //SensorCities.setSensorMode(SENS_OFF, SENS_CITIES_ULTRASOUND_5V);
  
    // mostramos el nivel de ruido..
    USB.print(F("Nivel de Ruido: "));
    USB.print(value_ruido);
    USB.println(F(" dBA"));
    
    // Lectura de la carga de la batería.
    PWR.getBatteryLevel();                      
    batteryLevel = PWR.getBatteryLevel();
    itoa(batteryLevel, batteryLevelString, 10); 

// Step 12. Message composition
    // Componemos el cuerpo del mensaje POST. Le incluimos MODSEN=000 ( WASPMOTE )
    sprintf(body,"I=%s&%s=%s&%s=%s&%s=%s",
        NumSerie ,
        TIME_STAMP, RTC.getTimestamp(),
        BATTERY, batteryLevelString,
        txt_MCP, t_value_ruido
     );    
        
// Step 13. Communication module to ON 
     // Preparar envío por GPRS. Definimos los datos del operador
    // 2. activates the 3G module:
    answer = _3G.ON();
    if ((answer == 1) || (answer == -3))
    {
        USB.println(F("3G module ready..."));

        // 3. set pin code:
        USB.println(F("Setting PIN code..."));
        // **** must be substituted by the SIM code
        if (_3G.setPIN(pin_code) == 1) 
        {
            USB.println(F("PIN code accepted"));
        }
        else
        {
            USB.println(F("PIN code incorrect"));
        }

        // 4. wait for connection to the network:
        answer = _3G.check(180);    
        if (answer == 1)
        { 
            USB.println(F("3G module connected to the network..."));            

            // 5. Sends the frame to Meshlium with POST
            //answer = _3G.sendHTTPframe( URL, port, frame.buffer, frame.length, POST);
            answer = _3G.readURLS(URL,port,body);

            // Checks the answer
            if ( answer == 1)
            {
                USB.println(F("Done"));  
                USB.println(_3G.buffer_3G);
            }
            else if (answer < -14)
            {
                USB.print(F("Failed. Error code: "));
                USB.println(answer, DEC);
                USB.print(F("CME error code: "));
                USB.println(_3G.CME_CMS_code, DEC);
            }
            else 
            {
                USB.print(F("Failed. Error code: "));
                USB.println(answer, DEC);
            } 
        }
        else
        {
            USB.println(F("3G module cannot connect to the network..."));
        }  
    }
    else
    {
        // Problem with the communication with the 3G module
        USB.println(F("3G module not started"));
    }

    // 7. powers off the 3G module
    _3G.OFF();
    delay(100);

//*****************************************************************
//    OTA standart loop
//*****************************************************************

  //Starts the 3G  module
  answerota = _3G.ON();

  //Checks the start sequence: 1 for correct start and -3 for correct start with low battery level
  if ((answerota == 1) || (answerota == -3))
  {
    USB.println(F("3G+GPS module ready..."));
    USB.println(F("Connecting to the network"));

    answerota = _3G.check(60);

    if (answerota == 1)
    {
      USB.println(F("3G+GPS module connected to the network"));
      USB.println(F("Starting OTA process"));

      answerota = _3G.requestOTA(ftp_address, ftp_port, ftp_user_name, ftp_password);

      // If OTA process fails, show the error code
      USB.print(F("Error code:"));
      USB.println( answerota, DEC);
    }
    else
    {
      USB.println(F("Error connecting to the network"));
    }
  }
  else
  {
    USB.println(F("Error starting the 3G+GPS module"));
  }

  _3G.OFF();
    
// Step 16. Entering Sleep Mode
    // Entramos en espera de 3MIN. La alarma del RTC nos despertará...
    USB.println(F("Entrando en espera ( 03:00 min )"));    
    PWR.deepSleep(sleepTime,RTC_OFFSET,RTC_ALM1_MODE1,ALL_OFF);
}

void FijaHora(void) {
    USB.ON();
    // 1. sets operator parameters
    _3G.set_APN(APN_Operador);

    // 2. activates the 3G module:
    answer =_3G.ON();
    if ((answer == 1) || (answer == -3))
    { 
        USB.println(F("3G module ready..."));

        // 3. set pin code:
        USB.println(F("Setting PIN code..."));
        // **** must be substituted by the SIM code
        if (_3G.setPIN("****") == 1) 
        {
            USB.println(F("PIN code accepted"));
        }
        else
        {
            USB.println(F("PIN code incorrect"));
        }

        // 4. wait for connection to the network:
        answer = _3G.check(180);
        if (answer == 1)
        {             
           USB.println(F("3G module connected to the network..."));

            USB.print(F("Getting URLS..."));

            // 5. gets URL from the solicited URL
            answer = _3G.readURLS(URLHora,port,request);

            // checks the answer
            if ( answer == 1)
            {
                USB.println(F("Done"));  
                USB.println(_3G.buffer_3G);
                RTC.setTime(_3G.buffer_3G);
            }
            else if (answer < -14)
            {
                USB.print(F("Failed. Error code: "));
                USB.println(answer, DEC);
                USB.print(F("CME error code: "));
                USB.println(_3G.CME_CMS_code, DEC);
            }
            else 
            {
                USB.print(F("Failed. Error code: "));
                USB.println(answer, DEC);
            }
        }
        else
        {    
          USB.println(F("3G module cannot connect to the network..."));     
        }
    }
    else
    {
        // Problem with the communication with the 3G module
        USB.println(F("3G module not started"));   
    }
    
    // 6. powers off the 3G module
    _3G.OFF(); 
    USB.OFF();
}
 
Thank you.

Re: P&S 3G v12 - OTA error code -21 with external FTP

Posted: Mon Oct 01, 2018 9:07 am
by libelium-dev
Hi,

Could you please share with us the output through the serial monitor with debug mode 1 enabled for 3G module? You can enable it inside Wasp3G.h file

Code: Select all

#define _3G_debug_mode	0
About OTA, you have to use prog001 file (without extension). Please try with that file and let us know if it works. Here you can find more information about OTA process.
http://www.libelium.com/downloads/docum ... amming.pdf

Regards

Re: P&S 3G v12 - OTA error code -21 with external FTP

Posted: Tue Oct 02, 2018 9:53 am
by smontoya
I change de file name, without extension. I didnt work. Here is the log of the code.

LOG:

Code: Select all

E#
RESTARTING
Program version: 10
Modulo Waspmote con ID => 419638338 iniciado.
3G module ready...
3G module connected to the network...
Getting URLS...Done
http/1.1 200 ok
date: tue, 02 oct 2018 07:44:54 gmt
server: apache/2.4.18 (ubuntu)
content-length: 20
content-type: text/html; charset=utf-8

18:10:02:03:09:44:5
Battery Level: 92 % | Battery (Volts): 4.1354837417 V
Nivel de Ruido: 50.0000000000 dBA
TS: Wed, 15/01/16, 09:18:08Time [Day of week, YY/MM/DD, hh:mm:ss]: Wed, 15/01/16, 09:18:14
3G module ready...
3G module connected to the network...
Done
http/1.1 200 ok
date: tue, 02 oct 2018 07:45:26 gmt
server: apache/2.4.18 (ubuntu)
set-cookie: phpsessid=fvns12eb2penuetg7e0j3obo50; path=/
expires: thu, 19 nov 1981 08:52:00 gmt
cache-control: no-store, no-cache, must-revalidate
pragma: no-cache
content-length: 36
content-type: text/html; charset=utf-8

WaspMote procesado correctamente.
O
3G+GPS module ready...
Connecting to the network
3G+GPS module connected to the network
Starting OTA process
Error code:-21
Entrando en espera ( 03:00 min )


Re: P&S 3G v12 - OTA error code -21 with external FTP

Posted: Wed Oct 03, 2018 8:45 am
by libelium-dev
Hi,

It seems that the debug isn't enabled. Please make sure that you changed the debug variable and upload the code to the node again.

You have to get the ota file that is located in the sketchbook when you export to binary. you don't have to remove the extension of the above file.

Regards