Problem geting float value to string, in project GPS tracking.

Hai everyone..

I'm beginer in arduino and I have some project that i some problem..
that's is some GPS Tracking Device with some simple system to get GPS coordinate ==>> sending all data to SMS.
but i have stuck on compiling the sketch getting error simultanously..
the problem is they can't get float value to the string...

This code that combine jeremyblum gps logger and mattxt GSM/GPRS/GPS Tracker..
so if it can work this device can be a tracking device and gps logger too..

How to solve this..?
Sorry about mess coding..
I attach this because so long.

this an error..

gpstrack.ino: In function 'boolean getURL()':
gpstrack:320: error: cannot convert 'String' to 'const char*' for argument '2' to 'char* strcat(char*, const char*)'

Hardware:

Arduino Uno R3
GPS Module EM-411
GSM/GPRS Shields iComSat v1.1

I'm so sorry about my bad english.
Any help appreciated.
Thanks.

gpstrack.ino (11.4 KB)

You are trying to use some variable which is of some class String, as an argument
to a function which is expecting an argument which is of type pointer to char.

michinyon:
You are trying to use some variable which is of some class String, as an argument
to a function which is expecting an argument which is of type pointer to char.

how to make that can run or how to solve...?
do you have some example code...?

or how to solve

Easy. Pass the function the correct kind of data.

do you have some example code

Do you have any capital letters?

Where is your code?

PaulS:

or how to solve

Easy. Pass the function the correct kind of data.

do you have some example code

Do you have any capital letters?

Where is your code?

I'm really sorry about capitalize letter..

I have attach my code in this post.
You can get on the end under my post.

//Define String
String Data_date_time = "invalid"; // the default data is "invalid"
String Data_lat = "invalid"; // the default data is "invalid"
String Data_lon = "invalid"; // the default data is "invalid"
String Data_alt = "invalid"; // the default data is "invalid"
String Data_spd = "invalid"; // the default data is "invalid"
String dataString =""; // for concatenate all data string up there (Data_lon, Data_Lat, Data_date_time)

Start with deleting all of these. Replace them with char pointers/char arrays.

  if (gsm_started){
    Serial.print("\nGPS Listening");
    gsm.listen();
    Serial.print("RAM:");
    Serial.println(freeMemory());

    if(gsm_started){

If gsm_started was true the first time, what would make it not true the second time?

PaulS:

//Define String

String Data_date_time = "invalid"; // the default data is "invalid"
String Data_lat = "invalid"; // the default data is "invalid"
String Data_lon = "invalid"; // the default data is "invalid"
String Data_alt = "invalid"; // the default data is "invalid"
String Data_spd = "invalid"; // the default data is "invalid"
String dataString =""; // for concatenate all data string up there (Data_lon, Data_Lat, Data_date_time)



Start with deleting all of these. Replace them with char pointers/char arrays.

I replace this code to..


char Data_date_time[32];
char Data_lat[10];
char Data_lon[10];
char Data_alt[5];
char Data_spd[5];
char dataString[100];




Next question is error "incompatible types in assignment of 'char [32]' to 'char [10]'" I,m not understand..
The marked error is here "if(Data_val == 1) Data_lat = sz;"
How to put the data into Data_lat..?

Next question is error "incompatible types in assignment of 'char [32]' to 'char [10]'" I,m not understand..

Nor do I. The error message contains a lot more information than you are copying, though, such as line number.

The marked error is here "if(Data_val == 1) Data_lat = sz;"

What is sz? You can't assign one array to another like that. strcat() and strcpy() bear investigation.

PaulS:

Next question is error "incompatible types in assignment of 'char [32]' to 'char [10]'" I,m not understand..

Nor do I. The error message contains a lot more information than you are copying, though, such as line number.

The marked error is here "if(Data_val == 1) Data_lat = sz;"

What is sz? You can't assign one array to another like that. strcat() and strcpy() bear investigation.

There is from here:

static void print_float(float val, float invalid, int len, int prec, int Data_val) // insert more argument about Data
{
  char sz[32];
  if (val == invalid)
  {
    strcpy(sz, "*******");
    sz[len] = 0;
    if (len > 0) 
      sz[len-1] = ' ';
    for (int i=7; i<len; ++i)
      sz[i] = ' ';
    Serial.print(sz);
    if(Data_val == 1) Data_lat = sz; 
    else if(Data_val == 2) Data_lon = sz; 
    else if(Data_val == 3) Data_alt = sz; 
    else if(Data_val == 4) Data_spd = sz; 
  }
  else
  {
    Serial.print(val, prec);
    if (Data_val == 1) Data_lat = dtostrf(val,10,5,dtostrfbuffer); // if SD_val is available (1) then put the captured data (sz) into variable (SD_lat)and use standard library "dtostrf" with (val) as value, 10 as long of character, dtostrfbuffer as buffer array.
    else if (Data_val == 2) Data_lon = dtostrf(val,10,5,dtostrfbuffer);  // if SD_val is available (2) then put the captured data (sz) into variable (SD_lon)and use standard library "dtostrf" with (val) as value, 10 as long of character, dtostrfbuffer as buffer array.
    else if (Data_val == 3) Data_alt = dtostrf(val,10,5,dtostrfbuffer);  // if SD_val is available (3) then put the captured data (sz) into variable (SD_lon)and use standard library "dtostrf" with (val) as value, 10 as long of character, dtostrfbuffer as buffer array.
    else if (Data_val == 4) Data_spd = dtostrf(val,10,5,dtostrfbuffer);  // if SD_val is available (4) then put the captured data (sz) into variable (SD_lon)and use standard library "dtostrf" with (val) as value, 10 as long of character, dtostrfbuffer as buffer array.
    int vi = abs((int)val);
    int flen = prec + (val < 0.0 ? 2 : 1);
    flen += vi >= 1000 ? 4 : vi >= 100 ? 3 : vi >= 10 ? 2 : 1;
    for (int i=flen; i<len; ++i)
      Serial.print(" ");
  }
  feedgps();
}

I want to get the value from "print_float" and then put into Data_val, after that convert the float to string by "dtostfr"..
Is that correct..?

I want to get the value from "print_float"...

Then, you seriously need to give some thought to renaming the function. That function should PRINT the value. Nothing more. Nothing less.

and then put into Data_val...

sz is an array. You can't assign an array to another array using the assignment operator (=). You can use strcat() or strcpy() depending on whether replace or concatenate is the goal.

Thanks Paul for help but now I have next question..
how to put the float value here:

  print_int(gps.satellites(), TinyGPS::GPS_INVALID_SATELLITES, 5);
  print_int(gps.hdop(), TinyGPS::GPS_INVALID_HDOP, 5);
  gps.f_get_position(&flat, &flon, &age); 
  print_float(flat, TinyGPS::GPS_INVALID_F_ANGLE, 9, 5, 1); //LATITUDE 
  print_float(flon, TinyGPS::GPS_INVALID_F_ANGLE, 10, 5, 2); //LONGITUDE 
  print_int(age, TinyGPS::GPS_INVALID_AGE, 5);

The value flat and flon to strcpy and strcat here..

boolean getURL(){
  if(returnurl){
    strcpy(url, "");
    strcpy(url, "http://maps.google.com/maps?q=");
    strcat(url, flat);
    //strcat(url, lngmdc);
    strcat(url, ",");
    strcat(url, flon);
    //strcat(url, latmdc);
    strcat(url, ", Speed: ");
    strcat(url, Data_spd);
    strcat(url, " km/h");
    strcat(url, ", Altitude: ");
    strcat(url, Data_alt);
    strcat(url, " grados");
  }

How to do that..? because that's result an error "can't convert float to *char or char" again.
Thanks before... I'm so sorry about my programming...