【问题标题】:how to send float value in url , im sending float value but getting Null values如何在 url 中发送浮点值,我发送浮点值但获取 Null 值
【发布时间】:2016-06-29 10:38:14
【问题描述】:

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

 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\"");

【问题讨论】:

  • 问。添加浮点数和字符串时会得到什么? A. 编译器错误!
  • 我没有收到编译错误。我在数据库中获取空值是因为它使用变量名而不是数据。双引号问题。我需要带有动态参数的api
  • 使用 snprintf 将值打印到字符串中(如果您想以 C++ 方式执行,则使用 stringstream)。

标签: c++ arduino iot


【解决方案1】:

您可以使用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 在 cmets 中所说,您可以使用 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 中的值在引号之间,所以我没有留下它们。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-14
    相关资源
    最近更新 更多