problem in concatenation between strings and variables

Hello everyone,

i want to send some data to my web page using GET METHOD. I am using a gsm shield to accomplish that and in a way it works, but only if i put the url with the values prefixed in the arduino code myself.

this is the code i am currently using to send the data in my db

  mySerial.println("AT+HTTPPARA=\"URL\",\"http://arduinowateringsystem.com/sensor_values.php?dat=3&temp=10&hum=20&soil=30&last=NOW()\"");

My goal though is to replace these values with variables. I've written this code but it doesn't seem to work.

  int dat=5;
  float temp=100;
  float hum=200;
  int soil=300;
  String last = "NOW()";
  String stringOne = "http://arduinowateringsystem.com/sensor_values.php?dat=";
  String stringTwo = stringOne + dat + "&temp=" + temp + "&hum=" + hum + "&soil=" + soil + "&last=" + last;
  mySerial.println("AT+HTTPPARA=\"URL\",\"strinOne,stringTwo \"");

Can anyone help me with this? thanks in advance!

you need to convert int and float to string type, you cant do ‘add’ operation with String and numerals.

You could try the below approach.

String two = stringOne + String(hum);

Check this link about String constructor.

It's a common mistake. You DON'T need to concatenate it first and then send it out. You can just send it out in the order you want. This will save you time and a lot of memory.

mySerial.print(F("AT+HTTPPARA=\"URL\",\"http://arduinowateringsystem.com/sensor_values.php?dat="));
mySerial.print(3);
mySerial.print(F("&temp="));
mySerial.print(10);
mySerial.print(F("&hum="));
mySerial.print(20
mySerial.print(F("&soil="));
mySerial.print(30);
mySerial.println(F("&last=NOW()\""));
[/quote]
Also added the F macro :)

thanks guys i will try what you suggest me to do..

This will save you time and a lot of memory.

Unless you are sending the data to a server, using client.print(). In that case, every print() sends a packet. Sending fewer packets is faster than sending lots of packets.

There is NO need to use Strings for this. sprintf(), dtostrf() and char arrays were invented for a reason.

But I don't think it does. Except from a bit more time between the parts there is no way for the device to see the difference between a single print and multiple prints. Most devices are simply triggered by the new line, which is only send after the last bit.