0

As per subject, how do I to manipulate the string passed through SoftwareSerial Print/Println function? The reason why is I tried to make the URL parameter dynamic in order to access different webpages.

*Note: The code snippet below are working fine if without using String variable

// This is working fine

SoftwareSerial iSerial(28, 29);
iSerial.println("AT+HTTPPARA=\"URL\",\"http://website.com/data1.php\"");      
delay(1000);
Serial.write(iSerial.read());
// This is not working 

SoftwareSerial gprsSerial(28, 29 );   
Int inputNumber;
String S1 = "AT+HTTPPARA=\"URL\",\"http://website.com/";
String S2 = String(inputNumber) + "data.php\"";
String_Variable =  S1+S2;
iSerial.println(String_Variable);      
delay(1000);
Serial.write(iSerial.read());

*Working means able to access the webpage via simcard using SIM900 (AT+HTTPPARA)

I even tried converting the string to array using malloc() and toCharArray() but it is still not working when I use the SoftwareSerial print function.

I'm new to Arduino. Kindly advise. Thanks! :)

Caey
  • 1
  • 2
  • use multiple `print` calls – Juraj Jan 20 '21 at 10:02
  • Hi @Juraj. do you mean something like this? `iSerial.println("AT+HTTPPARA=\"URL\",\"http://website.com/");` and `iSerial.println("data1.php\"");`? Is there any way to concatenate the strings and pass it as variable? because in the middle of the strings, there are integer input coming from different source. Sorry I've corrected my example in case it is misleading. Thanks for the reply :) – Caey Jan 20 '21 at 10:20
  • What is your serial printing at `iSerial.println(String_Variable);` exactly? – campescassiano Jan 20 '21 at 10:21
  • Hi @campescassiano, basically nothing/null. if I use `Serial.println(String_Variable)` (HardwareSerial), it will shows full String – Caey Jan 20 '21 at 10:26
  • I suspect the cause of the error is in `String(inputNumber)`. Try changing it to `String(to_string(inputNumber))`. You need to `#include ` in your code. – campescassiano Jan 20 '21 at 10:28
  • Also, `inputNumber` is not initialized, so it will be any value. – campescassiano Jan 20 '21 at 10:30
  • Are you sure about your `String_Variable`? Where is it defined? – campescassiano Jan 20 '21 at 10:32
  • `iSerial.print("AT+HTTPPARA=\"URL\",\"http://website.com/"); iSerial.print(inputNumber); iSerial.println("data1.php\"");` – Juraj Jan 20 '21 at 12:16
  • Hi @campescassiano apologize for the delay respond. there were. apparently I forgot to include `#include ` . Thanks for the advise :) – Caey Jan 22 '21 at 06:00
  • @Juraj it works. Thank you :) – Caey Jan 22 '21 at 06:01

0 Answers0