Show Posts
Pages: 1 ... 9 10 [11] 12 13 ... 27
151  International / Français / Re: Pourquoi ma variable est detruite au fure et a mseure on: July 15, 2013, 10:21:44 am
J'ai mis un commentaire à côte des
Quote
Serial.println(parameters);
Code:
int InetGSM::httpPOST(const char* server, int port, const char* path, const char* parameters, char* result, int resultlength)
{
        Serial.println(F("Starting to send"));
Serial.println(parameters); // Ceci lo=0.000000&la=0.000000&al=0.000000&ti=20130714213229.!Û%

Serial.println(parameters); // ceci lo=0.000000&la=0.000000&al=0.000000&ti=20130714213229.

  
  boolean connected=false;
  int n_of_at=0;
  char itoaBuffer[8];
  int num_char;
  char end_c[2];
  end_c[0]=0x1a;
  end_c[1]='\0';

  while(n_of_at<3){
 if(!connectTCP(server, port)){
  #ifdef DEBUG_ON
Serial.println("DB:NOT CONN");
#endif
    n_of_at++;
 }
 else{
connected=true;
n_of_at=3;
}
  }

  if(!connected){
   Serial.println(F("Not connected"));
   return 0;
  }

Serial.println(parameters); // Ceci affiche  : Ê
Serial.println(parameters); // Ceci affiche encore : Ê


  gsm.SimpleWrite("POST ");
  gsm.SimpleWrite(path);
  gsm.SimpleWrite(" HTTP/1.1\nHost: ");
  gsm.SimpleWrite(server);
  gsm.SimpleWrite("\n");
  gsm.SimpleWrite("User-Agent: Arduino\n");
  gsm.SimpleWrite("Content-Type: application/x-www-form-urlencoded\n");
  gsm.SimpleWrite("Content-Length: ");
  itoa(strlen(parameters),itoaBuffer,10);
  gsm.SimpleWrite(itoaBuffer);
  gsm.SimpleWrite("\n\n");
  gsm.SimpleWrite(parameters);
  gsm.SimpleWrite("\n\n");
  
  gsm.SimpleWrite(end_c);
 
 Serial.println(parameters); // et  Ceci affiche encore : Ê
 Serial.println(parameters); / et encore  Ceci affiche encore : Ê....
 
  switch(gsm.WaitResp(10000, 10, "SEND OK")){
case RX_TMOUT_ERR:
return 0;
break;
case RX_FINISHED_STR_NOT_RECV:
return 0;
break;
  }

 delay(50);
#ifdef DEBUG_ON
Serial.println("DB:SENT");
#endif

  int res= gsm.read(result, resultlength);
  Serial.println(F("Data sent"));
  
  //gsm.disconnectTCP();
  return res;
}

Selon les commentaire que j'ai mis dans le code, pourquoi 'parameters' perds sa valeurs???? alors qu'elle devrait rester
lo=0.000000&la=0.000000&al=0.000000&ti=20130714213222.000&ve=0.000000

Es-ce que j'ai fait un truc de faux dans ma function getGPSCoords() lorsque je retourne coords (return coords;)?

J'ai entendu parler de la declarer en static ou d'utiliser malloc(), mais la je suis largué car il faut que la taille de  char coords[] puisse s'adapter en fonction des tailles des positions GPS.

J'espère que vous m'avez compris et que j'ai été claire et si vous arriviez à me dépanner ca serat d'une très grande utilité!!

Milles mercis

Dite moi si vous avez besoin plsu de code!!!
152  International / Français / Pourquoi ma variable est detruite au fure et a mseure on: July 15, 2013, 10:14:01 am
Bonjour à tous,

Je suis sur un truc de fou mais je m'en sors avec perséveration  smiley.
Je suis pas trop expérimente c'est surement pourquoi, je prends tant de temps.....

J'ai une fonction qui doit me retourner un array. Je la declare comme ceci

Code:
char * getGPSCoords(void){
   // Je ne mets oas tous le code, a moins que vous en avez besoin.
   // Cette fonction fait appele a une autre pour collecter des positions GPS que je fusionne en une fonction. Etant donné que les valeurs et la longueur des valeur change, je calcule la taille de ces variable ainsi:


   // Je calcule la taille de toute les variables utilisée dans coords
   int le = strlen(lo)+strlen(la)+strlen(al)+strlen(ti)+strlen(ve)+strlen(en)+strlen(lon)+strlen(lat)+strlen(alt)+strlen(vel)+strlen(time);
   char coords[le];  
   /*
   char * coords;
   coords = (char*) malloc (le+1);
   */
   // C'est pourcela que je declare coords dans cette function car le peut changer et ainsi je suis sure de toujours avoir la taille de l'array en fonction des longeurs de toutes les variables correspondant aux positions GPS


   // A la fin je retourn coords pour l'exploiter plus loin
   // coords retournera 'lo=0.000000&la=0.000000&al=0.000000&ti=20130714213222.000&ve=0.000000'. Les zero, parce que je suis a un endorit qui ne choppe pas les positions, mais ca c'est pas grave pour le moment.
   return coords;
}

J'ai ensuite une action qui va envoyer les positions sur une base MySQL en POST, et c'est que les problèmes commencent.

Code:
// SEND DATA
// Quand je tape "send" dans mon terminal, il effectue ce code:
if(!strcmp(inSerial,"send")){
   #ifdef DEBUG
      Serial.println(F(""));
      Serial.println(F("SENDING COORDS TO THE REMOTE SERVER"));
      Serial.println(F("---------------------------------------"));
   #endif
        
   // Ceci affiche la valeur de mon array coords
   // Resultat : lo=0.000000&la=0.000000&al=0.000000&ti=20130714213222.000&ve=0.000000 (Dans le cas actuel, mon GPS ne capte pas de position, mais ca c'est pas grave pour le moment.
   Serial.println(getGPSCoords());


    // Ici c'est la fonction qui va envoyer "lo=0.000000&la=0.000000&al=0.000000&ti=20130714213222.000&ve=0.000000
" au serveur, et la les problème commence
    inet.httpPOST(host, port_post, path_post, getGPSCoords() , "Result", 4000);
    delay(10000);
 
}
Ici la fonction httpPOST(host,port_post, getGPSCoords,"Result",400). Je n'ai pas fait cette fonction. C'est une librairie que j'ai trouvé et qui semble pas mal...
Les problèmes commencent... et c'est peut etre tout simple à résoudre, mais j'ignore la parade.

NOTEZ BIEN que plus haut, Serial.println(getGPSCoords()), affiche bien ce que j'ai besoin, soit
Quote
lo=0.000000&la=0.000000&al=0.000000&ti=20130714213222.000&ve=0.000000

Le problème qu'au fure et à mesure que je fais un Serial.print(parameters), voir ci dessous, ma valeure
lo=0.000000&la=0.000000&al=0.000000&ti=20130714213222.000&ve=0.000000
est tronqué. Je perds des chifres.

Je mets le code de httpPOST(host,port_post, getGPSCoords,"Result",400) dans un reply afin d'avoir la place
153  Using Arduino / Programming Questions / Re: Do I need a special library for strcpy and strcat on: July 15, 2013, 09:00:33 am
Ok this is interrestinf but when I add "static", now it shoe an error

Code:
char* myFunction ()
{
 
int le = strlen(lo)+strlen(la)+strlen(al)+strlen(ti)+strlen(ve)+strlen(en)+strlen(lon)+strlen(lat)+strlen(alt)+strlen(vel)+strlen(time);
  /*
  char * coords;
  coords = (char*) malloc (le+1);
 */
 
  static char coords[le];
//do stuff with coords
 return coords;
}
Quote
storage size of 'coords' isn't a constant

I am a bit afraid because 'le', should not be a constant because it may change each period of time..  smiley-small
154  Using Arduino / Programming Questions / Re: Do I need a special library for strcpy and strcat on: July 15, 2013, 07:53:20 am
Dear PaulS,

It's interesting what you stated

So if I understood, it is not enought to just return a array, which has been declared and "filled" into an function. It's because it has been declare at the top of the script, we have to use malloc(). That right?

Then I should declare coords in that way (in the function)

Code:
char * coords;
  coords = (char*) malloc (100+1);
instead of
Code:
char coords[100];

May I ask you to correct me or show me an exemple, if I am wrong (I found this, wuth Google, so not sure)?

Many thank
155  Using Arduino / Programming Questions / Re: Do I need a special library for strcpy and strcat on: July 15, 2013, 06:49:39 am
It's works. So the Serial.print() display what I am waiting for but as I am a beginer, I am suspicious  smiley
156  Using Arduino / Programming Questions / Re: Do I need a special library for strcpy and strcat on: July 15, 2013, 06:32:22 am
Hello,

But at the end, this
Code:
char en[]="\0";
is good? I am confuse because it work...

I have a last question.

I declare the function, in that way, now, because I want it to return an array

Code:
char * getGPSCoords(void){
// coords is an array, I will not write all code
 
return coords;

}
Somewhere else in my code, I do this
Code:
Serial.println(getGPSCoords());

And it print the right value.

But when I want to copy the retun of getGPSCoords() into a char, like this
Code:
// To get the size of the return value
    int i = strlen(getGPSCoords());
// Define the size of value
  char value[i];
strcpy(value,getGPSCoords()); 
//value = getGPSCoords();
Serial.println(value);

value display nothing while Serial.println(getGPSCoords()); displays the right value.

However, I add a * at the function, like this
char * getGPSCoords(void){}

What did I wrong to use the return char value in a other function ? smiley-mr-green

Here is the function I need to use
Code:
inet.httpPOST(host, port_post, path_post, value , "Result", 1000);
I also try this, which would be the best
Code:
inet.httpPOST(host, port_post, path_post, getPGSCoords() , "Result", 1000);

Thank
157  Using Arduino / Programming Questions / Re: Do I need a special library for strcpy and strcat on: July 15, 2013, 04:42:58 am
All right, I do not belive!!!!

I think my problem is solved. So I just tried and it works since I make those change

1) I make all Serial.print to use the F() macro
2) I added char en[]="\0"; as I wrote before

I still can get fis from my GPS antena, because I am in a "heavy" buildig, but I am unpatient to try the code while I will be able to get gps fix.

I hope it is definitivly solved.

Thank for all, all, and all
158  Using Arduino / Programming Questions / Re: Do I need a special library for strcpy and strcat on: July 15, 2013, 03:23:45 am
Dear All,
I modified my code in order to have a terminator (\0).
I do niot know if it's a good reasonnement, ans I could not try it yet. But do you think it can be solve the issue?
(I will try later in the day, as soon as I can)

Code:
void getGPSCoords(){
  /*
  memset(&coords, 0 , sizeof(coords));
  memset(&lon, 0 , sizeof(lon));
  memset(&lat, 0 , sizeof(lat));
  memset(&alt, 0 , sizeof(alt));
  memset(&time, 0 , sizeof(time));
  memset(&vel, 0 , sizeof(vel));
  */
 
  #ifdef DEBUG
    stat=gps.getStat();
    if(stat==1){
      Serial.println("NOT FIXED");
    }else if(stat==0){
      Serial.println("GPS OFF");
    }else if(stat==2){
      Serial.println("2D FIXED");
    }else if(stat==3){
      Serial.println("3D FIXED");
    }
    delay(5000);
  #endif   
 
  //Get data from GPS
 
   gps.getPar(lon,lat,alt,time,vel);

 
  char lo[]="lo=";
  char la[]="&la=";
  char al[]="&al=";
  char ti[]="&ti=";
  char ve[]="&ve=";
  char en[]="\0"; // NEW ADD

 #ifdef DEBUG
    // I check if the the variable are filled and display the length
    Serial.print(lon); Serial.print(" "); Serial.println(strlen(lon));
    Serial.print(lat); Serial.print(" "); Serial.println(strlen(lat));
    Serial.print(alt); Serial.print(" "); Serial.println(strlen(alt));
    Serial.print(vel); Serial.print(" "); Serial.println(strlen(vel));
    Serial.print(time); Serial.print(" "); Serial.println(strlen(time));
    Serial.print(lo); Serial.print(" "); Serial.println(strlen(lo));
    Serial.print(la); Serial.print(" "); Serial.println(strlen(la));
    Serial.print(al); Serial.print(" "); Serial.println(strlen(al));
    Serial.print(ti); Serial.print(" "); Serial.println(strlen(ti));
    Serial.print(ve); Serial.print(" "); Serial.println(strlen(ve));
    Serial.print(en); Serial.print(" "); Serial.println(strlen(en));
    Serial.println("-----");
  #endif
 
  int le = strlen(lo)+strlen(la)+strlen(al)+strlen(ti)+strlen(ve)+strlen(en)+strlen(lon)+strlen(lat)+strlen(alt)+strlen(vel)+strlen(time);
  Serial.println(le);
 
  char coords[le]; // NEW CHANGE
 
  strcpy(coords,lo);
  strcat(coords,lon);
 
  strcat(coords,la);
  strcat(coords,lat);
 
  strcat(coords,al);
  strcat(coords,alt);

  strcat(coords,ti);
  strcat(coords,time);
 
  strcat(coords,ve);
  strcat(coords,vel);
 
  strcat(coords,en); // NEW ADD
 
 
  #ifdef DEBUG
    Serial.print(F("Coords : "));                               
    Serial.println(coords);
 //   Serial.println(strlen(coords));
  #endif
 
 
}
159  Using Arduino / Programming Questions / Re: Do I need a special library for strcpy and strcat on: July 15, 2013, 02:15:35 am
Thank for all, for all of your suggesrion.

I am very happy, because I got a success solution but not at 100%. There is a little bug at the end, but I am on a good solution.

I modify my code, as the following:
I move the initialisation of char coords[]; to the getGPSCoords() function
Code:
void getGPSCoords(){
  /*
  memset(&coords, 0 , sizeof(coords));
  memset(&lon, 0 , sizeof(lon));
  memset(&lat, 0 , sizeof(lat));
  memset(&alt, 0 , sizeof(alt));
  memset(&time, 0 , sizeof(time));
  memset(&vel, 0 , sizeof(vel));
  */
 
// Get static on GPS status/availability
  #ifdef DEBUG
    stat=gps.getStat();
    if(stat==1){
      Serial.println("NOT FIXED");
    }else if(stat==0){
      Serial.println("GPS OFF");
    }else if(stat==2){
      Serial.println("2D FIXED");
    }else if(stat==3){
      Serial.println("3D FIXED");
    }
    delay(5000);
  #endif   
 
  //Get data from GPS
   gps.getPar(lon,lat,alt,time,vel);

  #ifdef DEBUG
    // I check if the the variable are filled and display the length
    Serial.print(lon); Serial.print(" "); Serial.println(strlen(lon));
    Serial.print(lat); Serial.print(" "); Serial.println(strlen(lat));
    Serial.print(alt); Serial.print(" "); Serial.println(strlen(alt));
    Serial.print(vel); Serial.print(" "); Serial.println(strlen(vel));
    Serial.print(time); Serial.print(" "); Serial.println(strlen(time));
    Serial.println("-----");
  #endif
 
   char lo[]="lo=";
   char la[]="&la=";
   char al[]="&al=";
   char ti[]="&ti=";
   char ve[]="&ve=";
 
   // Count the number of caracter of the coords + the string, which are now, type of char (and not string any more)
   int le = strlen(lo)+strlen(la)+strlen(al)+strlen(ti)+strlen(ve)+strlen(lon)+strlen(lat)+strlen(alt)+strlen(vel)+strlen(time);
   // Disèplay the number of caracter
   Serial.println(le);
 // Iniatiate the coords with the exact number of caracter, whatever if lat, lon, alt change of length
 // Add +1 for the terminator
  char coords[le+1];
 
  // Concatenate all char varaiable
  strcpy(coords,lo);
  strcat(coords,lon);
 
  strcat(coords,la);
  strcat(coords,lat);
 
  strcat(coords,al);
  strcat(coords,alt);

  strcat(coords,ti);     
  strcat(coords,time);   
 
  strcat(coords,ve);     
  strcat(coords,vel);
 
  #ifdef DEBUG
    Serial.print(F("Coords : "));                               
    Serial.println(coords);
    Serial.println(strlen(coords));
  #endif
 
 
}

I am very happy, because coords display the correct value. here is my display:
I am in a train and I can not get fix, It's the reason why we have 0.000000, but it does not matter, for my issue
Quote
GETTING GPS COORDS
--------------------------------
In progress, wait...
NOT FIXED
0.000000 8
0.000000 8
0.000000 8
0.000000 8
20130714223032.000 18
-----
(the lenght of char lo, la, al, ti and ve are not display here)
69
Coords : lo=0.000000&la=0.000000&al=0.000000&ti=20130714223032.000&ve=0.000000

Code:
The last problem:
After, the terminal display the result of
Quote
Coords : lo=0.000000&la=0.000000&al=0.000000&ti=20130714223032.000&ve=0.000000
the program stop working, like if it freeze.
Would you have an idea, why it freeze juste at the "end"?
160  International / Français / Re: Comment puis-je envoyer un array en post on: July 15, 2013, 12:33:34 am
Aussi, ca ca ne marche pas non plus

Code:
String message = "test1"+"test2";
Le message d'erreur : "Invalid  operands of types 'const char [5]' and 'const char [5]' to binary 'operateu' +"

J'essaye de concatener des String, maintenant.
161  International / Français / Re: Comment puis-je envoyer un array en post on: July 14, 2013, 03:41:18 pm
Merci pour ta réponse.
Je deviens un peu fou  smiley

je fais ceci:
Code:
String fix = "long=" + String(lon) + "&lat=" + String(lat) + "&alti=" + String(alt) + "&vel=" + String(vel) + "&time=" + String(time);


 Serial.println(fix);
 Serial.println(fix.length());
fix.toCharArray(coords, 109);
//(j'aimerais remplacé 109 par fix.length()+1
//char coords[fix.length()+1];
//fix.toCharArray(coords, fix.length()+1);
// Le +1 pour laisser une place au terminateur, comme tu me l a expliqué

pourquoi fix n'affiche rien? Il affiche vide.
(lon, lat, alt, vel, time, sont des char.
162  Using Arduino / Programming Questions / Re: Do I need a special library for strcpy and strcat on: July 14, 2013, 03:14:33 pm
Hello acboother,

Yes, I debug a bit as you explain.
Yesterday evening, I discivered that it work until this
Code:
/*
  strncat(coords,alt,COORDSSIZ);  //61
 
  strcat(coords,"&t=");        //64
  strncat(coords,time,20);      //84
 
  strcat(coords,"&vel=");        //89
  strncat(coords,vel,COORDSSIZ);  //114
  */

Code:
void getGPSCoords(){
  #ifdef DEBUG
    stat=gps.getStat();
    if(stat==1){
      Serial.println("NOT FIXED");
    }else if(stat==0){
      Serial.println("GPS OFF");
    }else if(stat==2){
      Serial.println("2D FIXED");
    }else if(stat==3){
      Serial.println("3D FIXED");
    }
    delay(5000);
  #endif   
 
  //Get data from GPS
 
    gps.getPar(lon,lat,alt,time,vel);
 
  Serial.println(lon);
  Serial.println(lat);
  Serial.println(alt);
  Serial.println(vel);
  Serial.println(time);
  Serial.println("-----");
 

 
  strcpy(coords,"long=");
  strncat(coords,lon,COORDSSIZ); //21
 
  strcat(coords,"&lat=");        //25
  strncat(coords,lat,COORDSSIZ);//40

  strcat(coords,"&alti=");        //46
/*
  strncat(coords,alt,COORDSSIZ);  //61
 
  strcat(coords,"&t=");        //64
  strncat(coords,time,20);      //84
 
  strcat(coords,"&vel=");        //89
  strncat(coords,vel,COORDSSIZ);  //114
  */
 
  // I am also trying this, but coords display nothing
  //snprintf(coords, sizeof coords,"lon=%s,lat=%s,alti=%s,vel=%s,time=%s",lon,lat,alt,vel,time);
 
  #ifdef DEBUG
    Serial.print(F("Coords : "));                               
    Serial.println(coords);
  #endif

I am also traing with this
Code:
char coords[]="";
snprintf(coords, sizeof coords,"lon=%s,lat=%s,alti=%s,vel=%s,time=%s",lon,lat,alt,vel,time);
Serial.println(coords);
With this, the code work and do not crash or restart. But coords display nothing
163  Using Arduino / Programming Questions / Re: Do I need a special library for strcpy and strcat on: July 14, 2013, 02:57:10 pm
Really really thank for your help.

What do you mean ba the header?

The function is in another file. I past all of this function. I hope I answered to your question
(I have not wrote this function. It's a library I found.)
Code:
char GPSGSM::getPar(char *str_long, char *str_lat, char *str_alt, char *str_time, char *str_speed)
{
char ret_val=0;
char *p_char;
char *p_char1;
gsm.SimpleWriteln("AT+CGPSINF=0");
gsm.WaitResp(5000, 100, "OK");
if(gsm.IsStringReceived("OK"))
ret_val=1;

//longitude
p_char = strchr((char *)(gsm.comm_buf),',');
p_char1 = p_char+1;  //we are on the first char of longitude
p_char = strchr((char *)(p_char1), ',');
if (p_char != NULL) {
          *p_char = 0;
    }
strcpy(str_long, (char *)(p_char1));

// latitude
p_char++;
p_char1 = strchr((char *)(p_char), ',');
if (p_char1 != NULL) {
          *p_char1 = 0;
    }
strcpy(str_lat, (char *)(p_char));

// altitude
p_char1++;
p_char = strchr((char *)(p_char1), ',');
if (p_char != NULL) {
          *p_char = 0;
    }
strcpy(str_alt, (char *)(p_char1));

// UTC time
p_char++;
p_char1 = strchr((char *)(p_char), ',');
if (p_char1 != NULL) {
          *p_char1 = 0;
    }
strcpy(str_time, (char *)(p_char));

// TTFF
p_char1++;
p_char = strchr((char *)(p_char1), ',');
if (p_char != NULL) {
          *p_char = 0;
    }

// num
p_char++;
p_char1 = strchr((char *)(p_char), ',');
if (p_char1 != NULL) {
          *p_char1 = 0;
    }

// speed
p_char1++;
p_char = strchr((char *)(p_char1), ',');
if (p_char != NULL) {
          *p_char = 0;
    }
strcpy(str_speed, (char *)(p_char1));

return ret_val;
}
164  Using Arduino / Programming Questions / Re: Do I need a special library for strcpy and strcat on: July 14, 2013, 02:35:53 pm
Here is my full full code

the function
void getGPSCoords(){} and
gps.getPar(lon,lat,alt,time,vel);
is at the bottom

and also look below
// GET GPS COORDS,
I call the function getGPSCoords, here, while I type "gps" in my terminal

Code:
#include "SIM900.h"
#include <SoftwareSerial.h>
#include "inetGSM.h"
#include "sms.h"
//#include "call.h"
#include "gps.h"

InetGSM inet;
//CallGSM call;
SMSGSM sms;
GPSGSM gps;

#define DEBUG

char number[]="0041000000000";  //Destination number

// INET
char apn[] = "internet"; // access-point name for GPRS
char username[] = "";
char password[] = "";
//char ip = "92.104.xx.xxx"; // IP address of server we're connecting to
int port_get = 80; // Port to use
int port_post = 80; // Port to use
char host[] = "xxx.dyndns.org"; // required in HTTP 1.1 - what's the name of the host at this IP address?
char path_post[] = "/opt/updatesql.php";
/*
const int buttonPin = 10;     // the number of the pushbutton pin
int buttonState = 0;
buttonState = digitalRead(buttonPin);
*/

// GPS

char coords[127];
#define COORDSSIZ 15
char lon[COORDSSIZ];
char lat[COORDSSIZ];
char alt[COORDSSIZ];
char time[20];
char vel[COORDSSIZ];
char msg1[5];
char msg2[5];

char stat;
char inSerial[20];
int i=0;
boolean started=false;

void setup()
{
  //Serial connection.
  Serial.begin(9600);
  #ifdef DEBUG
    Serial.println(F(""));
    Serial.println(F("\n--------------------------------"));
    Serial.println(F("Starting SIM908."));
    Serial.println(F("--------------------------------"));
    Serial.println(F("Please wait..."));
  #endif
  //Start configuration of shield with baudrate.
  //For http uses is raccomanded to use 4800 or slower.
 
  if (gsm.begin(2400)){
   
    #ifdef DEBUG
      Serial.println("\nstatus=READY\n");
    #endif
   
    gsm.forceON(); //To ensure that SIM908 is not only in charge mode
    started=true; 
   
  }else{
    #ifdef DEBUG
      Serial.println("\nstatus=IDLE");
    #endif
  }
  if(started){
    #ifdef DEBUG
      Serial.println(F("GPS"));
      Serial.println(F("--------------------------------"));
    #endif
    //GPS attach
    if (gps.attachGPS()){
      Serial.println("status=GPS_READY");
    }else{
      Serial.println("status=GPS_ERROR_NOT_ATTACHED");
    }
   
    #ifdef DEBUG
      Serial.println(F("\nGSM"));
      Serial.println(F("--------------------------------"));
    #endif
   
    #ifdef DEBUG
      Serial.println("Waiting for 20sec before trying to attach GSM");
    #endif
    delay(20000); //Time for fixing
   
   
   
    // GSM ATTACH
    if (inet.attachGPRS("internet", "", "")){
      #ifdef DEBUG
        Serial.println(F("status=GSM_ATTACHED"));
      #endif
      //Read IP address.
      gsm.SimpleWriteln("AT+CIFSR");
      delay(5000);
      //Read until serial buffer is empty.
      gsm.WhileSimpleRead();
    }else{
      Serial.println(F("status=GSM_ERROR_NOT_ATTACHED"));
    }
    #ifdef DEBUG
      Serial.println("\nWaiting for 1sec");
    #endif
    delay(1000);
   
   
   
    #ifdef DEBUG
      enterCommand();
    #endif
   
  }else{
    #ifdef DEBUG
      Serial.println(F("Not started"));
     #endif
  }
};

void loop()
{
  /*
  buttonState = digitalRead(buttonPin);
  // check if the pushbutton is pressed.
  // if it is, the buttonState is HIGH:
  if (buttonState == HIGH) {     
    digitalWrite(GSM_ON, HIGH);
    delay(2000);
    digitalWrite(GSM_ON, LOW);
    delay(5000); 
  }
  else {
  }
  */
  //Read for new byte on serial hardware,
  //and write them on NewSoftSerial.
  serialhwread();
  //Read for new byte on NewSoftSerial.
  serialswread();
};

void serialhwread(){
  i=0;
  if (Serial.available() > 0){           
    while (Serial.available() > 0) {
      inSerial[i]=(Serial.read());
      delay(10);
      i++;     
    }
   
    inSerial[i]='\0';
    if(!strcmp(inSerial,"/END")){
      Serial.println("_");
      inSerial[0]=0x1a;
      inSerial[1]='\0';
      gsm.SimpleWriteln(inSerial);
    }
    //Send a saved AT command using serial port.
    if(!strcmp(inSerial,"test")){
      Serial.println(F("BATTERY TEST 1"));
      Serial.println(F("--------------------------------"));
      gps.getBattInf(msg1,msg2);
      Serial.println(msg1);
      Serial.println(msg2);
      Serial.println(F("BATTERY TEST 2"));
      Serial.println(F("--------------------------------"));
      gps.getBattTVol(msg1);
      Serial.println(msg1);
      Serial.println(F("GPS TEST"));
      Serial.println(F("--------------------------------"));
      getGPSCoords();
      Serial.println(F(""));
     
      #ifdef DEBUG
          enterCommand();
      #endif
    }
   
     // SEND SMS
    if(!strcmp(inSerial,"sms")){
      #ifdef DEBUG
        Serial.println(F("SENDING SMS"));
        Serial.println(F("--------------------------------"));
        Serial.println(F("In progress, wait..."));
      #endif
      if (sms.SendSMS(number, "Did you get that SMS?")){
        #ifdef DEBUG
          Serial.println("SMS sent OK\n");
        #endif
       }
       
       #ifdef DEBUG
          enterCommand();
        #endif
    }
   
    // GET GPS COORDS
    if(!strcmp(inSerial,"gps")){
      #ifdef DEBUG
        Serial.println(F("GETTING GPS COORDS"));
        Serial.println(F("--------------------------------"));
        Serial.println(F("In progress, wait..."));
      #endif
      getGPSCoords();
     
      #ifdef DEBUG
          enterCommand();
      #endif
    }
   
    // GET DATA FROM SERVER
    if(!strcmp(inSerial,"get")){
     
      #ifdef DEBUG
        Serial.println(F(""));
        Serial.println(F("The collection of data from the server, is not ready yet"));
       #endif
     /*
      #ifdef DEBUG
        Serial.print(F("Getting data from (Host/Port) "));
        Serial.print(host);
        Serial.print(F(" /  "));
        Serial.println(port_get);
      #endif
      */
     
      /*
      //TCP Client GET, send a GET request to the server and
      //save the reply.
      numdata=inet.httpGET(host, port_get, "/", msg, 50);
      //Print the results.
      Serial.println(F("\nNumber of data received:"));
      Serial.println(numdata); 
      Serial.println(F("\nData received:"));
      Serial.println(msg);
      */
     
       enterCommand();
    }
   
    // SEND DATA
    if(!strcmp(inSerial,"data")){
        #ifdef DEBUG
          Serial.println(F(""));
          Serial.println(F("Sending GPS coords to the remote server"));
          Serial.println(F("---------------------------------------"));
          Serial.println(F("Script not ready"));
         #endif
      /*
        inet.httpPOST(host, port_post, path_post, coords , "Result", 1000);
        delay(10000);
       */
        enterCommand();
    }
   
   
    //Read last message saved.
    if(!strcmp(inSerial,"msg")){
      Serial.println(msg1);
    }
    else{
      Serial.println(inSerial);
      gsm.SimpleWriteln(inSerial);
    }   
    inSerial[0]='\0';
  }
}

void serialswread(){
  gsm.SimpleRead();
}

void getGPSCoords(){
  #ifdef DEBUG
    stat=gps.getStat();
    if(stat==1){
      Serial.println("NOT FIXED");
    }else if(stat==0){
      Serial.println("GPS OFF");
    }else if(stat==2){
      Serial.println("2D FIXED");
    }else if(stat==3){
      Serial.println("3D FIXED");
    }
    delay(5000);
  #endif   
 
  //Get data from GPS
 
  gps.getPar(lon,lat,alt,time,vel);
 
  Serial.println(lon);
  Serial.println(lat);
  Serial.println(alt);
  Serial.println(time);
  Serial.println(vel);
  /*
  String fix = "long=" + String(lon) + "&lat=" + String(lat) + "&alti=" + String(alt) + "&vel=" + String(vel) + "&time=" + String(time) + "\0";
//  char *fix[144] = {"long=" + String(lon) + "&lat=" + String(lat) + "&alti=" + String(alt) + "&vel=" + String(vel) + "&time=" + String(time) + "\0"};

  char *coord;
  coord = (char*)fix;
  */

 
  strcpy(coords,"long=");
  strncat(coords,lon,COORDSSIZ); //21
 
  strcat(coords,"&lat=");        //25
  strncat(coords,lat,COORDSSIZ);//40

  strcat(coords,"&alti=");        //46

  strncat(coords,alt,COORDSSIZ);  //61
 
  strcat(coords,"&t=");        //64
  strncat(coords,time,20);      //84
 
  strcat(coords,"&vel=");        //89
  strncat(coords,vel,COORDSSIZ);  //114
 
 
  #ifdef DEBUG
    Serial.print(F("Coords : "));                               
    Serial.println(coords);
  #endif
 
}

void enterCommand(){
    Serial.println("\nEnter a command :");
    Serial.println(F("--------------------------------"));
    Serial.println(F("sms  => Send SMS"));
    Serial.println(F("data => Send GPS coords to the server"));
    Serial.println(F("get  => Get data from server"));
    Serial.println(F("gps  => Display GPS coords"));
    Serial.println(F("test => Test system"));
    Serial.println(F("--------------------------------\n"));
   
}
165  Using Arduino / Programming Questions / Re: Do I need a special library for strcpy and strcat on: July 14, 2013, 02:19:48 pm
Dear UKHeliBob

Thank for your proposition.

I am just confused with this, as you showed
Code:
char lon[15] = {"712.585044"};
  char lat[15] = {"4705.587531"};
  char alt[15] = {"505.911530"};
  char time[20] = {"20130713210510.000"};
  char vel[15] = {"0.000000"};

I can not hardly code this {"712.585044"};

The value are provided to lon, lat, alt, time, vel by a function
Code:
gps.getPar(lon,lat,alt,time,vel);
and all lon, lat, alt.. etc are char variable

I just declare
Code:
char coords[200]; //I gave this time a very large value, but it should be around 114
#define COORDSSIZ 15
char lon[COORDSSIZ];
char lat[COORDSSIZ];
char alt[COORDSSIZ];
char time[20];
char vel[COORDSSIZ];
and then the function give the value to the variable.

Code:
void getGPSCoords(){
  #ifdef DEBUG
    stat=gps.getStat();
    if(stat==1){
      Serial.println("NOT FIXED");
    }else if(stat==0){
      Serial.println("GPS OFF");
    }else if(stat==2){
      Serial.println("2D FIXED");
    }else if(stat==3){
      Serial.println("3D FIXED");
    }
    delay(5000);
  #endif   
 
  //Get data from GPS
 
  gps.getPar(lon,lat,alt,time,vel);
 
// Those Serial.println, print correctly the value of the variables
  Serial.println(lon);
  Serial.println(lat);
  Serial.println(alt);
  Serial.println(time);
  Serial.println(vel);
  /*
  String fix = "long=" + String(lon) + "&lat=" + String(lat) + "&alti=" + String(alt) + "&vel=" + String(vel) + "&time=" + String(time) + "\0";
//  char *fix[144] = {"long=" + String(lon) + "&lat=" + String(lat) + "&alti=" + String(alt) + "&vel=" + String(vel) + "&time=" + String(time) + "\0"};

  char *coord;
  coord = (char*)fix;
  */

  strcpy(coords,"long=");
  strncat(coords,lon,COORDSSIZ); //21 => This fonction is to limit the size of lon to 15. It uses the first 15 caracters, if there are more...
 
  strcat(coords,"&lat=");        //25
  strncat(coords,lat,COORDSSIZ);//40

  strcat(coords,"&alti=");        //46
  strncat(coords,alt,COORDSSIZ);  //61
 
  strcat(coords,"&t=");        //64
  strncat(coords,time,20);      //84
 
 
  strcat(coords,"&vel=");        //89
  strncat(coords,vel,COORDSSIZ);  //114
 
 
 
 
  #ifdef DEBUG
    Serial.print(F("Coords : "));                               
    Serial.println(coords);
  #endif
 
}
Pages: 1 ... 9 10 [11] 12 13 ... 27