通过ethienet正从Arduino的数据,并存储在数据库 [英] getting data from arduino and stored in database through ethienet

查看:255
本文介绍了通过ethienet正从Arduino的数据,并存储在数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到来自Arduino的数据,并通过ethienet存储在数据库中。但是,当我从Arduino的价值ambientemp。它表现出正确的值,当我连续监视器上进行测试。但是当我用sprintf()我得到-3275或0值,这是不正确的值。这里是我的草图部分code,请帮助...这里是男人做他的项目。草图上的串口montior结果是:ambientTemp 23.55,然后让我/getData/temp.php?t=-3278复制了一些他:<一href=\"http://scouris.word$p$pss.com/2010/09/10/temperature-sensing-with-arduino-php-and-jquery/#more-27\"相对=nofollow>获取数据并存储到mysql

 无效的getData(){
  双ambientTemp = 23.55; //以方便我分配ambientTemp值。
无符号长previousMillis = 0;
无符号长currentMillis = 0;
长间隔= 10000;
  焦炭strURL [70];
   EthernetClient客户端;
  //如果有一个成功的连接,发送HTTP POST请求
   currentMillis =米利斯();
  如果(currentMillis - previousMillis&GT;间隔){
    previousMillis = currentMillis;  如果(client.connect(服务器,80)){
    Serial.println(获取连接数据......);    //client.println(\"GET /getData/temp.php?t=%d,temp HTTP / 1.1);
   //延迟(10000);
     Serial.println(ambientTemp);
  Serial.println(ambientTemp);
    sprintf的(strURL,GET /getData/temp.php?t=%d\",ambientTemp);
    延迟(50000);    client.print(strURL);
    client.println();
   // client.print(strURL);
    Serial.print(strURL);  }
  其他{
    //如果无法建立连接:
    Serial.println(连接失败);
    Serial.println(断开);
    client.stop();
  }
}
}


解决方案

您需要在C画幅规格读了。 %D是指采取corresponsding变量(ambientTemp你的情况),跨preT它作为一个整数。那么,运行code做的是看它弥补了你的双字节,和跨preting整数那些一首2。不是你想要什么....使用%F作为格式说明...

I am getting data from arduino and stored in database through ethienet. But when i got value ambientemp from arduino. it showed correct value when i tested on serial monitor. but when I use sprintf() I got -3275 or 0 value, which it is not correct value. Here is my partial code in sketch, please help...Here is guy doing his project. The result on Sketch serial montior is: ambientTemp 23.55 and then GET /getData/temp.php?t=-3278 I copied some of him: 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();
  }
}
}

解决方案

You need to read up on C format specifications. "%d" means take the corresponsding variable (ambientTemp in your case) and interpret it as an integer. So what the runtime code is doing is looking at the bytes which make up your double, and interpreting the first 2 of those an in integer. Not what you want.... use "%f" as a format specifier...

这篇关于通过ethienet正从Arduino的数据,并存储在数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆