0

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);
asked Jan 25, 2019 at 5:41
1
  • Which arduino board do you use? Commented Jan 25, 2019 at 8:52

1 Answer 1

1

+ on const char * increments the pointer. only String has + overloaded as concatenation of the right operand (not left). so "abc" + str + "efg" will not work even if str is String. What will work is String("abc") + str + "efg", but small Strings will fragment the heap memory of the MCU very fast and the sketch will crash.

Print the parts directly to serialSIM800 or use snprintf to build the strings or try CStringBuilder from my StreamLib

answered Jan 25, 2019 at 6:11

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.