You need to capture the return value of the TellWater()
in a variable.
Here I am assuming TellWater()
return float. You need to convert it to string.
float water_value = TellWater();
String water_value_str;
water_value_str = String(f);
After you convert the sensor data to string, you need to perform string concatenation to prepare final output string.
String output_string = "api_key=QI8G7PVTC2BVIREC&field1=" + water_value_str + "\r\n";
Serial.print(output_string);
You should not escape back slash \
in \\r\\n
. This will cause compiler to interpret the statement as character \
(0x5c) and character r
(0x72) instead as \r
(0x0D) (carriage-return). Similarly \\n
will be interpreted as character \
(0x5c) and character n
(0x6e) instead as \n
(0x0A) (line-feed) causing your GSM module to wait for data as it has not received line-ending characters (\r\n).