Problem with GPRS/GPS append data

Everything about programming the platform and using the Waspmote API
Post Reply
pablo_chumacero
Posts: 18
Joined: Sat Mar 19, 2016 12:58 am

Problem with GPRS/GPS append data

Post by pablo_chumacero » Fri Nov 25, 2016 12:54 am

Hello,

I have a waspmote v1.2, a smart water board and a GPRS / GPS module. I want to upload the data measured by the smart water card and the GPS location to an FTP server via the GPRS / GPS module. I have managed to attach the measured data to a .txt file and save it to the SD card. Subsequently the file is uploaded to FTP, however, it only does so the first time the program is started, then an error occurs when attaching the data to the .txt file. I would greatly appreciate your help.

This is my code:

Code: Select all

#include <WaspSensorSW.h>         
#include "WaspGPRS_SIM928A.h"
#include <WaspSD.h>



char apn[] = "claro.pe";
char login[] = "claro";
char password[] = "claro";

int answer; 
int SDHOH;   
int SDHOH1;
    
float temperatura;
float ORPValue;
float ORPValue1;
float DOVol;
float DOValue;
float ECRes;
float ECValue;
char valor1[10];
char valor2[10];
char valor3[10];
char valor4[10];
char valor5[60];
char valor6[120];
uint8_t sd_answer; 

 #define calibration_offset 0.0
// Calibration of the sensor in normal air
#define air_calibration 2.65
// Calibration of the sensor under 0% solution
#define zero_calibration 0.0

// Value 1 used to calibrate the sensor
#define point1_cond 10500
// Value 2 used to calibrate the sensor
#define point2_cond 40000

// Point 1 of the calibration 
#define point1_cal 197.00
// Point 2 of the calibration 
#define point2_cal 150.00

DOClass DOSensor;
pt1000Class TemperatureSensor;
ORPClass ORPSensor;
conductivityClass ConductivitySensor;

SdFile file;

char filename[]="SINERGIA.TXT";
void setup()
{
  USB.ON();
  SD.ON();
  DOSensor.setCalibrationPoints(air_calibration, zero_calibration);
  ConductivitySensor.setCalibrationPoints(point1_cond, point1_cal, point2_cond, point2_cal);
  Water.ON();

  if(SD.del(filename)) 
  {
    USB.println(F("file deleted"));
  }
  else 
  {
    USB.println(F("file NOT deleted"));  
  }

   if(SD.create(filename))
  {
    USB.println(F("file created"));
  }
  else 
  {
    USB.println(F("file NOT created"));  
  }  

  GPRS_SIM928A.set_APN(apn, login, password);
  GPRS_SIM928A.show_APN();

}
void Sensores()
{
  //GPRS_SIM928A.ON(); 

 
    
  temperatura= TemperatureSensor.readTemperature();
  Utils.float2String (temperatura,valor1, 2);
  //USB.print("Temperatura:");
  //USB.println(valor1);

  // ORP sensor
  ORPValue = ORPSensor.readORP();
  ORPValue1 = ORPValue - calibration_offset;
  Utils.float2String (ORPValue1,valor2, 2);
  //USB.print("ORP:");
  //USB.println(valor2);

   //  DO sensor
  DOVol = DOSensor.readDO();
  DOValue = DOSensor.DOConversion(DOVol);
  Utils.float2String (DOValue,valor3, 2);
  //USB.print(F("DO: "));
  //USB.println(valor3);

 ECRes = ConductivitySensor.readConductivity();
 ECValue = ConductivitySensor.conductivityConversion(ECRes);
 Utils.float2String (ECValue,valor4, 2);
 //USB.print(F("Conductivity: "));
 //USB.println(valor4);


 sprintf(valor6,"Temperatura =%s & Conductividad = %s & Oxigenos Dis = %s & ORP = %s \n",valor1,valor2,valor3,valor4);

 
 SDHOH= SD.openFile(filename,&file, O_APPEND);
  if( SDHOH == 1 )
    {
    USB.print(F("OPEN correct \n"));
    }
    else
    {
    USB.println(F("OPEN error \n"));
    }
 
 sd_answer = SD.append(filename,valor6);
 
    if( sd_answer == 1 )
    {
    USB.println(F("Append correct"));
    }
    else
    {
    USB.println(F("\n1 - append error"));
    }
  SD.showFile(filename);

  SDHOH1= SD.closeFile(&file);
   if( SDHOH1 == 1 )
    {
    USB.print(F("close correct \n"));
    }
    else
    {
    USB.println(F("close error \n "));
    }
    
  delay(10000);
  //printString(valor5,0);
  //delay(1000);
}

void loop()
{

  SD.ls();
  Sensores();

  answer = GPRS_SIM928A.ON(); 
    if ((answer == 1) || (answer == -3))
    {
        USB.println(F("GPRS_SIM928A module ready..."));

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

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

            // 5. configures GPRS Connection for HTTP or FTP applications:
            answer = GPRS_SIM928A.configureGPRS_HTTP_FTP(1);
            if (answer == 1)
            {

                USB.println(F("Uploading the file ..."));

                // 6a. uploads file from SD card to the FTP server:
                answer = GPRS_SIM928A.uploadFile(filename, "/SDisruptor.txt", "*******", "********", "*********", "***", 1);
                SDHOH1= SD.closeFile(&file);
   if( SDHOH1 == 1 )
    {
    USB.print(F("close correct"));
    }
    else
    {
    USB.println(F("close error"));
    }
                // checks the answer
                if (answer == 1)
                {
                    USB.println(F("Upload done"));
                }
                else if(answer < -40)
                {
                    USB.print(F("Upload failed. Error code: "));
                    USB.println(answer, DEC);
                    USB.print(F("CME error code: "));
                    USB.println(GPRS_SIM928A.CME_CMS_code, DEC);
                }
                else 
                {
                    USB.print(F("Upload failed1. Error code: "));
                    USB.println(answer, DEC);
                }

                delay(5000);
            }
            else
            {
                USB.println(F("Configuration failed. Error code:"));
                USB.println(answer, DEC);
            }
        }
        else
        {
            USB.println(F("GPRS_SIM928A module cannot connect to the network"));     
        }
    }
    else
    {
        USB.println(F("GPRS_SIM928A module not ready"));    
    }
    
    // 7. powers off the GPRS_SIM928A module
    GPRS_SIM928A.OFF(); 
   SDHOH1= SD.closeFile(&file);
     if( SDHOH1 == 1 )
    {
    USB.print(F("close correct"));
    }
    else
    {
    USB.println(F("close error"));
    }
    SD.ls();
   // USB.println(F("Sleeping..."));

    // 8. sleeps one hour
    //PWR.deepSleep("00:01:00:00", RTC_OFFSET, RTC_ALM1_MODE1, ALL_OFF);
    
}
And this is my output:

Code: Select all

E#
file deleted
file created
APN: claro.pe
LOGIN: claro
PASSWORD: claro
SYSTEM~1/     
SINERGIA.TXT   0
HOH.TXT        162
OPEN correct 
Append correct

-------------------
Temperatura =-0.35 & Conductividad = -2.04 & Oxigenos Dis = 0.00 & ORP = -5020.98 

-------------------
CLOSE correct 
GPRS_SIM928A module ready...
Setting PIN code...
PIN code incorrect
GPRS_SIM928A module connected to the network...
Uploading the file ...
close error
Upload done
close error
OPEN error 


1 - append error

-------------------

-------------------
CLOSE error 
 
GPRS_SIM928A module ready...
Setting PIN code...
PIN code incorrect
GPRS_SIM928A module connected to the network...
Uploading the file ...
close error
Upload done
close error
OPEN error 


1 - append error

-------------------

-------------------
CLOSE error 
 
GPRS_SIM928A module ready...
Setting PIN code...
PIN code incorrect
GPRS_SIM928A module connected to the network...
Uploading the file ...
close error
Upload done
close error
OPEN error 


1 - append error

-------------------

-------------------
CLOSE error 
 
GPRS_SIM928A module ready...
Setting PIN code...
PIN code incorrect
GPRS_SIM928A module connected to the network...
Uploading the file ...
close error
Upload done
close error
OPEN error 


1 - append error

-------------------

-------------------
CLOSE error 
 
GPRS_SIM928A module ready...
Setting PIN code...
PIN code incorrect
GPRS_SIM928A module connected to the network...
Uploading the file ...
close error
Upload done
close error
OPEN error 


1 - append error

-------------------

-------------------
CLOSE error 
 
GPRS_SIM928A module ready...
Setting PIN code...
PIN code incorrect

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

Re: Problem with GPRS/GPS append data

Post by libelium-dev » Fri Nov 25, 2016 10:19 am

Hi,

Try including in the loop SD.ON(); because the uploadFile function turn OFF the SD when it finishes to upload the file.

Regards

pablo_chumacero
Posts: 18
Joined: Sat Mar 19, 2016 12:58 am

Re: Problem with GPRS/GPS append data

Post by pablo_chumacero » Mon Nov 28, 2016 3:41 am

libelium-dev wrote:Hi,

Try including in the loop SD.ON(); because the uploadFile function turn OFF the SD when it finishes to upload the file.

Regards
Thank you so much. Now the code it's okay. :D

Now, I have other question:

I want recieve data from UART port, then I will use this data from UART to set time sleep on my waspmote. So, I am using the function "beginSerial(115200,0)" to open UART port and "serialRead(0)" to read data send from UART port. But I want that while UART port don't send data my program wait for it and the code don't continue. My output must stop after "Inserte tiempo de muestreo" but this continue and don't wait for data.

This is my code:

Code: Select all

//LIBRERÍAS
#include <WaspXBee868.h>              //LIBRERÍA DE XBEE868
#include <WaspFrame.h>                    //LIBRERIA DE FRAMES


char filename[13];
int val;
char sleeptime[50];
int slepp;

void setup()
{
  beginSerial(115200,0);                                                                                 
  xbee868.ON(); 
  USB.ON();

                                                                                      
}
void loop()
{
  USB.print(F("Insertar Tiempo de Muestreo\n"));  
  
   while(!serialAvailable(0));
   if (serialAvailable(0) > 0) 
   {
   val = serialRead(0);
   USB.println(val);
   switch(val)
     {
      case 49:
      slepp=10;
      USB.print(F("Tiempo de Muestreo 10Min\n"));
      sprintf(sleeptime,"00:00:%02u:00",slepp);
      USB.print(sleeptime);
      break;
      
      case 50:
      slepp=30;
      USB.print(F("Tiempo de Muestreo 30Min\n"));
      sprintf(sleeptime,"00:00:%02u:00",slepp);
      USB.print(sleeptime);
      break;
      
      case 51:
      slepp=01;
      USB.print(F("Tiempo de Muestreo 1Hora\n"));
      sprintf(sleeptime,"00:%02u:00:00",slepp);
      USB.print(sleeptime);
      break;
      
      default:
      
      break;
      }

   }

  delay(2000); 
}

And this is my output:

Code: Select all

E#
Insertar Tiempo de Muestreo
0
Insertar Tiempo de Muestreo
0
Insertar Tiempo de Muestreo
0
Insertar Tiempo de Muestreo
0
Insertar Tiempo de Muestreo
0
Insertar Tiempo de Muestreo
0
I want that my program wait after the message "Insertar Tiempo de Muestro" but this don't wait and print 0 when it isn't right.

Regards.

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

Re: Problem with GPRS/GPS append data

Post by libelium-dev » Mon Nov 28, 2016 12:08 pm

Hi,

Do you want to receive the data through the serial monitor? If so, try to use something like the following

Code: Select all

while (!USB.available()) {
}
delay(100);

val = USB.read();
.
.
.
Regards

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest