如何在url发送浮动值,我发送浮动值,但得到空值

how to send float value in url , im sending float value but getting Null values

本文关键字:空值 url      更新时间:2023-10-16

我想发送值并插入值到数据库中,但我得到空值。

 float PHValue = Value/10;
  float DOValue= 12.22;
  gprsSerial.println("AT+HTTPPARA="URL","http://itempurl.com/smartpond/AddTemprature?WaterTemperature=""+celsius+""&PHValue=""+PHValue+""&DOValue=""+DOValue+""&currentTime=06-30-2016"");

您可以使用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("&currentTime=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"
          "&currentTime=06-30-2016"", celsius, PHValue, DOValue);
gprsSerial.println(command);

注意:我不确定你是否希望url中的值在引号之间,所以我没有。