mysql - 从arduino获取数据并通过ethienet存储到数据库中

标签 mysql arduino

我从arduino获取数据并通过ethienet存储在数据库中。但是当我从arduino获得环境变量值时。当我在串行监视器上测试时它显示了正确的值。但是当我使用 sprintf() 时,我得到 -3275 或 0 值,这不是正确的值。这是我的草图部分代码,请帮忙...这是一个正在做他的项目的人。 Sketch串行监视器上的结果是:ambientTemp 23.55然后GET/getData/temp.php?t=-3278 我复制了他的一些:getting data and stored it into mysql

void getData() {
  double ambientTemp=23.55; //to make it easy I assign ambientTemp a value.
unsigned long previousMillis = 0;
unsigned long currentMillis = 0;
long interval = 10000; 
  char strURL[70];


   EthernetClient client;
  // If there's a successful connection, send the HTTP POST request
   currentMillis = millis();
  if(currentMillis - previousMillis > interval) {
    previousMillis = currentMillis;

  if (client.connect(server, 80)) {
    Serial.println("get data connecting...");

    //client.println("GET /getData/temp.php?t=%d,temp HTTP/1.1");
   // delay(10000);
     Serial.println("ambientTemp");
  Serial.println(ambientTemp);
    sprintf(strURL,"GET /getData/temp.php?t=%d",ambientTemp);
    delay(50000);

    client.print(strURL);
    client.println();
   // client.print(strURL);
    Serial.print(strURL);



  } 
  else {
    // If you couldn't make a connection:
    Serial.println("Connection failed");
    Serial.println("Disconnecting.");
    client.stop();
  }
}
}

最佳答案

您需要阅读 C 格式规范。 “%d”表示采用相应的变量(在您的情况下为ambientTemp)并将其解释为整数。因此,运行时代码所做的就是查看组成 double 的字节,并解释其中的前 2 个整数。不是你想要的......使用“%f”作为格式说明符......

关于mysql - 从arduino获取数据并通过ethienet存储到数据库中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20128437/

相关文章:

php - 在 php 和 mysql 中对数据进行排序多少?

mysql - 计算cakephp 3.x中数据库记录的总价

php - 为什么没有任何东西被插入到我的 MySQL 表中?

arduino - Arduino 引导加载程序可以在所有 AVR 上工作吗?

arduino - FastLED 和简单计数器的问题

c++ - 编译Arduino代码(NodeMCU)时出错

mysql - 在 MySQL 中永久设置 auto_increment_offset

MySQL 如果存在则选择,但如果不存在则显示 no 值

c# - 从串口读取的数据是分离的。代码+结果里面

ubuntu - ESP8266 - 终端连接不起作用,但 Python 脚本