Having a really bad day with String concat

Having really bad day with concat. I'm not quite sure where i did wrong..
Have a look at my function below.

void sim900aSendHttp(String bid, String lati, String longi) {
  Serial.println("BUSID:"+bid+",LAT:"+lati+"LONG:"+longi);
  String httpget = "http://uumresearch.com/bustracking/update_location.php?busid="+bid+"&latitude="+lati+"&longitude="+longi+"";
  //String httpget = "http://uumresearch.com/bustracking/update_location.php?busid=KDF8860&latitude=6.533415&longitude=106.33345";
  Serial.println(httpget);
  serialSIM800.println("AT+HTTPPARA=\"URL\",\"" + httpget + "\"");
  delay(3000);
  serialSIM800.println("AT+HTTPACTION=0");
  delay(8000);
}

The problem is with:

String httpget = "http://uumresearch.com/bustracking/update_location.php?busid="+bid+"&latitude="+lati+"&longitude="+longi+"";

where serial monitor only shows

http://uumresearch.com/bustracking/update_location.php?busid=KDF8860

missing "lat" and "longi" variables in the string concat.

Both variable confirmed available to the function as printed by

Serial.println("BUSID:"+bid+",LAT:"+lati+"LONG:"+longi);

Sorry managed to solved this problem just now...maybe this can be useful for someone...apparently Arduino cannot take two or more String at the same time..how ever building the strings manage to get the string properly build...

String httpget = "http://uumresearch.com/bustracking/update_location.php?busid="+bid;
  httpget +="&latitude="+lati;
  httpget +="&longitude="+longi;

Back to drawing board...how Arduino handle string is pretty weird...

void sim900aSendHttp(String bid, String lati, String longi) {
  Serial.println("BUSID:"+bid+",LAT:"+lati+"LONG:"+longi);
  String httpget = "http://uumresearch.com/bustracking/update_location.php?busid="+bid;
  httpget +="&latitude="+lati;
  httpget +="&longitude="+longi;
  //String httpfull = httpget;
  //String httpget = "http://uumresearch.com/bustracking/update_location.php?busid=KDF8860&latitude=6.533415&longitude=106.33345";
  Serial.println(httpget);
  serialSIM800.println("AT+HTTPPARA=\"URL\",\"" + httpget + "\"");
  delay(3000);
  serialSIM800.println("AT+HTTPACTION=0");
  delay(8000);
  Serial.println(httpget+"COMPL");
}

My httpget successfully build the query but then when I tried to send using HTTPPARA it seems truncate.. Heres the output

http://uumresearch.com/bustracking/update_location.php?busid=kdf8860&latitude=6.44517867&longitude=100.42433717

http://uumresearch.com/bustracking/update_location.php?busid=kdf8860COMPL

Any help would be appreciated...pulling my hair now...

Declare the String first:
String httpget = “” ;
Then use the String operators like ‘+’ etc.
httpget = “x” + “y” + “z” ;
And try:
Serial.println( String( httpget + "COMPL") );

Edit:
See the post from Juraj below

6v6gt:
Declare the String first:
String httpget = “” ;

Then use the String operators like ‘+’ etc.
httpget = “x” + “y” + “z” ;

And try:
Serial.println( String( httpget + "COMPL") );

Still same output...String stop at first concat variable..

I made an error and will delete the post I made. See the answer from Juraj.

This is known to work:

  String str = "" ;
  str = String("x") + String("y")  + String("z") ;
  Serial.println( str ) ;

  String str2 = "" ;
  str2.concat( "a" ) ;
  str2.concat( "b" ) ;
  str2.concat( "c" ) ;
  Serial.println( str2 ) ;

I've tried both but seems I did managed to build the string that I needed...however the weird thing is when I'm sending through serial AT command using my httpget variable it seems only to send the first concat variable

 serialSIM800.println("AT+HTTPPARA=\"URL\",\"" + httpget + "\"");

my serial printout the following just the string i wanted and this is the full get url that i need to send

http://uumresearch.com/bustracking/update_location.php?busid=kdf8860&latitude=6.44539233&longitude=100.42419283

However the AT command I believed only send

http://uumresearch.com/bustracking/update_location.php?busid=kdf8860

And the weird thing when I copyt the string from my serial terminal the full link it only appear paste just the above string..

6v6gt:
I made an error and will delete the post I made. See the answer from Juraj.

This is known to work:

  String str = "" ;

str = String("x") + String("y")  + String("z") ;
  Serial.println( str ) ;

String str2 = "" ;
  str2.concat( "a" ) ;
  str2.concat( "b" ) ;
  str2.concat( "c" ) ;
  Serial.println( str2 ) ;

slumberjer:
I've tried both but seems I did managed to build the string that I needed...however the weird thing is when I'm sending through serial AT command using my httpget variable it seems only to send the first concat variable

 serialSIM800.println("AT+HTTPPARA=\"URL\",\"" + httpget + "\"");

my serial printout the following just the string i wanted and this is the full get url that i need to send

http://uumresearch.com/bustracking/update_location.php?busid=kdf8860&latitude=6.44539233&longitude=100.42419283

However the AT command I believed only send

http://uumresearch.com/bustracking/update_location.php?busid=kdf8860

And the weird thing when I copyt the string from my serial terminal the full link it only appear paste just the above string..

in String httpget = "http://uumresearch.com/bustracking/update_location.php?busid="+bid+"&latitude="+lati+"&longitude="+longi+""; the httpget String object handles the = and + operators. so you build the String

here serialSIM800.println("AT+HTTPPARA="URL","" + httpget + """);
you have no String object as 'left' operator to start the concatenation because the parameter of println used is of type const char* based on constant string "AT+HTTPPARA="URL",""

another way of looking at is to build the complete String in one variable, say myString, print it out to verify it:

Serial.println( myString ) ;

Then send it:

serialSIM800.println( myString ) ;

Also, look at the String 'reserve' command to reserve enough space for the largest String to avoid heap fragmentation.

myString.reserve( 80 ) ; // for example

Juraj..

The AT COMMAND requires serial command

AT+HTTPPARA="URL","http:\\yoururlhere.com\myphp?test=123"

so to be used in arduino code serial print with custom URL...

 serialSIM800.println("AT+HTTPPARA=\"URL\",\""+httpget+ "\"");

or I'm do it wrong?

slumberjer:
Juraj..

The AT COMMAND requires serial command

AT+HTTPPARA="URL","http:\\yoururlhere.com\myphp?test=123"

so to be used in arduino code serial print with custom URL...

 serialSIM800.println("AT+HTTPPARA=\"URL\",\""+httpget+ "\"");

or I'm do it wrong?

you have my answer on Arduino SE

Juraj:
arduino ide - Having really weird experience with string concat - Arduino Stack Exchange

Well I've tried your CStringBuilder...but doesn't seems to work for me..with conversion error..this is really messing my head now...

Does this work for you ?

String ATcomm ;


void sim900aSendHttp(String bid, String lati, String longi) {
  ATcomm = "AT+HTTPPARA=\"URL\",\"" ;
  ATcomm += "http://uumresearch.com/bustracking/update_location.php?busid=" ;
  ATcomm += bid ;
  ATcomm += "&latitude="+lati ;
  ATcomm += "&longitude="+longi ;
  ATcomm += "\"" ;
  Serial.println(ATcomm);
  serialSIM800.println(ATcomm);
  delay(3000);
  serialSIM800.println("AT+HTTPACTION=0");
  delay(8000);
}


void setup() {
  Serial.begin(115200) ;

  ATcomm.reserve(150 ) ;
  String bid = "KDF8860" ;
  String lati = "6.533415" ;
  String longi = "106.33345" ;

  sim900aSendHttp( bid,  lati,  longi) ;

}

void loop() {
 
}

Do you need to use Strings or would strings work ?

slumberjer:
Well I've tried your CStringBuilder...but doesn't seems to work for me..with conversion error..this is really messing my head now...

check the example

6v6gt:
Does this work for you ?

String ATcomm ;

void sim900aSendHttp(String bid, String lati, String longi) {
 ATcomm = "AT+HTTPPARA="URL","" ;
 ATcomm += "http://uumresearch.com/bustracking/update_location.php?busid=" ;
 ATcomm += bid ;
 ATcomm += "&latitude="+lati ;
 ATcomm += "&longitude="+longi ;
 ATcomm += """ ;
 Serial.println(ATcomm);
 serialSIM800.println(ATcomm);
 delay(3000);
 serialSIM800.println("AT+HTTPACTION=0");
 delay(8000);
}

void setup() {
 Serial.begin(115200) ;

ATcomm.reserve(150 ) ;
 String bid = "KDF8860" ;
 String lati = "6.533415" ;
 String longi = "106.33345" ;

sim900aSendHttp( bid,  lati,  longi) ;

}

void loop() {

}

Nope...I really hope it works...I print out the ATComm and it print out the

AT+HTTPPARA="URL","http://uumresearch.com/bustracking/update_location.php?busid=kdf8860&latitude=6.44506133&longitude=100.42425883"

but to the AT command only get

AT+HTTPPARA="URL","http://uumresearch.com/bustracking/update_location.php?busid=kdf8860

thus updating my mysql table with empty field of latitude and longitude.. The string build nicely but then AT command stop at first GET passing variable...

I've tried with the URL without building it and it works..But that just static url i need the build get url...

very strange indeed...

Will call it a night...

It may be something does not like the "&" character in the URL. Try replacing it with %26 and see if you get any further.

6v6gt:
It may be something does not like the "&" character in the URL. Try replacing it with %26 and see if you get any further.

URL Encoded Characters

Still the same...

Finally I can put this to history...

due to my own stupid mistake. I read the bus id from EEPROM and mistakenly store the all the value even it is not there.

void readData() {
  EEPROM.begin(512);
  Serial.println("Reading From EEPROM..");
  for (int i = 0; i < 20; i++) {
    if (EEPROM.read(i)> 0){
      busid += char(EEPROM.read(i));  
    }
  }
  EEPROM.end();
  Serial.println("Bus ID: " + busid);
}

Change my read memory function as above then the problem solved. The build URL store 13 empty spaces the the string information thus creating this problem..I solved this by printing each value from my string one by one and surprisingly the 13 empty character shows up that keep hogging my url...

So my code is ok now..

Thanks all..