可以單獨使用print()像派:
int n_decimals = 3;
float PHValue = Value/10;
float DOValue= 12.22;
gprsSerial.print("AT+HTTPPARA=\"URL\",\"http://itempurl.com/smartpond/AddTemprature?WaterTemperature=");
gprsSerial.print(celsius, n_decimals);
gprsSerial.print("&PHValue=");
gprsSerial.print(PHValue, n_decimals);
gprsSerial.print("&DOValue=");
gprsSerial.print(DOValue, n_decimals);
gprsSerial.println("¤tTime=06-30-2016\"");
隨着n_decimals
要打印的小數位的數量。
或者像@stark在評論中說,你可以使用snprintf
生成您的AT命令:
char command[256];
float PHValue = Value/10;
float DOValue= 12.22;
snprintf(command, sizeof(command), "AT+HTTPPARA=\"URL\",\""
"http://itempurl.com/smartpond/AddTemprature?"
"WaterTemperature=%f&PHValue=%f&DOValue=%f"
"¤tTime=06-30-2016\"", celsius, PHValue, DOValue);
gprsSerial.println(command);
注:我不知道,如果你想在URL中值引號之間去的,所以我沒有離開他們。
問:當你添加一個浮點數和一個字符串時,你會得到什麼? A.編譯器錯誤! – stark
即時通訊沒有收到編譯錯誤。即時通訊在數據庫中獲得空值,因爲它將變量名稱而不是數據。問題在雙引號中。我需要帶動態參數的API。 –
使用snprintf將值打印到字符串中(或者如果您想用C++方式執行,請使用stringstream)。 – stark