Pages: [1] 2   Go Down
Author Topic: How Can I merge char variable  (Read 2143 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Sr. Member
****
Karma: 0
Posts: 399
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Good evening all,

I need to merge some char into a another.

Here are my declaration
Code:
char coords[100];
char lon[15];
char lat[15];
char alt[15];
char time[20];
char vel[15];
At the end, I would like to have this

Code:
coords = "lat="+lat+"&long="+lon+"&alt="+alt+"&speed=&course="+val+"&date=2013-04-25&time="+time+";

By the way, the time is returning with in this format
Code:
20130615220230.000

How can I get it a human readable?

Cheers
Logged

Il ne suffit pas de tout savoir, la persévérance, c'est déjà presque tout!

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 303
Posts: 26354
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

strcat?
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Offline Offline
Sr. Member
****
Karma: 0
Posts: 399
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I am not sure, if it works

this return me only the time value
Code:
strcpy (coords,"lat=");
      strcpy (coords,lat);
      strcpy (coords,"&long=");
      strcpy (coords,lon);
      strcpy (coords,"&alt=");
      strcpy (coords,alt);
      strcpy (coords,"&speed=");
      strcpy (coords,"");
      strcpy (coords,"&course=");
      strcpy (coords,vel);
      strcpy (coords,"&date=");
      strcpy (coords,"2013-06-16");
      strcpy (coords,"&time=");
      strcpy (coords,time);

Serial.println(coords);
Logged

Il ne suffit pas de tout savoir, la persévérance, c'est déjà presque tout!

Offline Offline
Full Member
***
Karma: 2
Posts: 143
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

try this:

Code:
char coords[50];

snprintf(coords,50,"lat=%s&long=%s&alt=%s&speed=%s&course=%s&date=%s&time=%s",lat,lon,alt,speed,vel,date,time);

edit: variable name
« Last Edit: June 15, 2013, 05:49:58 pm by j514 » Logged

a][+ ascii express, 110/300 novation cat, xmodem

Ontario Canada
Offline Offline
Newbie
*
Karma: 0
Posts: 14
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Or, use the String class with operator+, such as

String message = String("lat") + String(lat)  ...and so on
Logged

Offline Offline
Sr. Member
****
Karma: 0
Posts: 399
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Si when I uncomment this
Code:
char coords[100];
//snprintf(coords,100,"lat=%s&long=%s&alt=%s&speed=%s&course=%s&date=%s&time=%s",lat,lon,alt,"",vel,"2013-06-22",time);
the program free. So stop at the begining
Logged

Il ne suffit pas de tout savoir, la persévérance, c'est déjà presque tout!

California
Offline Offline
Faraday Member
**
Karma: 88
Posts: 3384
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

the program free. So stop at the begining

What?
Logged

Offline Offline
Sr. Member
****
Karma: 0
Posts: 399
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The terminal show the progress but it stop at the 5ft line. Nothing happen. When I comment the line, the code/terminal continue in his right process
Logged

Il ne suffit pas de tout savoir, la persévérance, c'est déjà presque tout!

California
Offline Offline
Faraday Member
**
Karma: 88
Posts: 3384
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The terminal show the progress but it stop at the 5ft line. Nothing happen. When I comment the line, the code/terminal continue in his right process

What terminal? What 5ft. line?
Logged

Offline Offline
Sr. Member
****
Karma: 0
Posts: 399
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

This is when is commented
Code:
----------------------
Starting SIM908.
----------------------
Please wait...
DB:ELSE
DB:ELSE
DB:ELSE
DB:CORRECT BR
Turn on

status=READY

Attaching GSM
--------------
DB:ALREADY HAVE AN IP
status=ATTACHED
GSM RAEDY TO GO!

Attaching GPS
--------------
status=GPS READY TO GO!
sms => Send SMS
data => Send data to the server
get => Get data from server
gps => Get GPS coords
test => Test system


This is when it uncommented (not good)
Code:
----------------------
Starting SIM908.
----------------------
Please wait...
DB:ELSE
DB:ELSE
DB:ELSE
DB:CORRECT BR
Logged

Il ne suffit pas de tout savoir, la persévérance, c'est déjà presque tout!

Offline Offline
Sr. Member
****
Karma: 0
Posts: 399
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

To resume,
I have this
Code:
gps.getPar(lon,lat,alt,time,vel);
and it should be in the coords variable of this
Code:
inet.httpPOST(host, port_post, path_post, coords , "Result", 1000);
But I hav to add URL varaiable like this
Code:
coords = "lat="+lat+"&long="+lon+"&alt="+alt+"&speed=&course="+val+"&date=2013-04-25&time="+time+";

 smiley-slim smiley
Logged

Il ne suffit pas de tout savoir, la persévérance, c'est déjà presque tout!

California
Offline Offline
Faraday Member
**
Karma: 88
Posts: 3384
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

And how are we supposed to know what's wrong when you've only posted no more than 4 lines of your code?
Logged

Offline Offline
Full Member
***
Karma: 2
Posts: 143
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Si when I uncomment this
Code:
char coords[100];
//snprintf(coords,100,"lat=%s&long=%s&alt=%s&speed=%s&course=%s&date=%s&time=%s",lat,lon,alt,"",vel,"2013-06-22",time);
the program free. So stop at the begining

"" is invalid, use a variable.  Here, I've done the work for you.

Code:
void setup()
{
  char coords[100];
  char lon[15];
  char lat[15];
  char alt[15];
  char vel[15]; // speed
  char crs[15]; // course
  char date[20]; 
  char time[20];
 
    // make sure each variable is initialized or sprintf will return junk
    strcpy(lat,"99.9");
    strcpy(lon,"11.1");
    strcpy(alt,"22");
    strcpy(vel,"55mph");
    strcpy(crs,"2.5NE");
    strcpy(time,"21:01:01");
    strcpy(date,"6/15/2013");
    snprintf(coords,100,"lat=%s&long=%s&alt=%s&speed=%s&course=%s&date=%s&time=%s",lat,lon,alt,vel,crs,date,time);
   
    Serial.begin(9600);
    Serial.println(coords);
    Serial.end();
}

void loop() {}
Logged

a][+ ascii express, 110/300 novation cat, xmodem

Offline Offline
Sr. Member
****
Karma: 0
Posts: 399
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello All
thank for your answers and help, but I am afraid it did not solve my issue.

I am sorry if I have been not clear enough.

Here is a resume

Code:
// GPS
char coords[100];
char lon[15];
char lat[15];
char alt[15];
char time[20];
char vel[15];
char msg1[5];
char msg2[5];

This collect the GPS coords
Code:
gps.getPar(lon,lat,alt,time,vel);
Then from now, I have the longitude (lon) the latitude (lat) etc. No worries for sppeed and course, I will see it later.

I have to send the cords to a remote server and for this I use this function
Code:
inet.httpPOST(host, port_post, path_post, coords , "Result", 1000);
      delay(10000);
Coords is the char variable which must contain the value.

If I code
Code:
coords = "lat="+lat+"&long="+lon+"&alt="+alt+"&vel="+val+"&time="+time;
inet.httpPOST(host, port_post, path_post, coords , "Result", 1000);

This works fine, but now I have to replace the "10.000", "20.000" etc by the value provided by the GSP.
So I tryied this

Code:
coords = "lat="+lat+"&long=20.0000&alt=30.000&speed=&vel=40.000&time=20130609062400.097;
but this does not work.
I have this error message
Quote
Invalid operands of types 'const char[5]' and 'char[15]' to binary 'operator' +

That's it
 smiley
« Last Edit: June 16, 2013, 01:24:32 am by pierrot10 » Logged

Il ne suffit pas de tout savoir, la persévérance, c'est déjà presque tout!

Offline Offline
Sr. Member
****
Karma: 0
Posts: 399
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ok, I solved my problem this way
Code:
  gps.getPar(lon,lat,alt,time,vel);
     
      strcpy (coords,"lat=");
      strcat (coords,lat);
     
      strcat (coords,"&long=");
      strcat (coords,lon);
     
      strcat (coords,"&alt=");
      strcat (coords,alt);
     
      strcat (coords,"&vel=");
      strcat (coords,vel);
     
      strcat (coords,"&time=");
      strcat (coords,time);

Now I have a last question.

time diaply this : 20130609062400.097

how can I have it in a readable format?

many thank
Logged

Il ne suffit pas de tout savoir, la persévérance, c'est déjà presque tout!

Pages: [1] 2   Go Up
Jump to: