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);
-
Which arduino board do you use?Jot– Jot2019年01月25日 08:52:37 +00:00Commented Jan 25, 2019 at 8:52
1 Answer 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