如何在 MySQL 中将温度、压力、湿度传感器集成到一个 table 中?

How to integrate temperature, pressure, humidity sensors into a single table in MySQL?

我想要详细的分步过程和代码,了解如何将时间戳中包含的温度传感器、压力传感器、湿度传感器集成到数据库中的单个 table 中。我希望每 15 分钟将这些值输入 MySQL 数据库。

这里是教程See here。 更进一步,你需要有这样的表格,

//
CREATE TABLE `your_database`.`tempmoi` (
`id` INT( 255 ) NOT NULL AUTO_INCREMENT ,
`temperature` VARCHAR( 255 ) NOT NULL ,
`pressure` VARCHAR( 255 ) NOT NULL ,
`humidity` VARCHAR( 255 ) NOT NULL ,
`timestamp` VARCHAR( 255 ) NOT NULL ,
`moi1` VARCHAR( 255 ) NOT NULL ,
PRIMARY KEY ( `id` )
) ENGINE = MYISAM ;

更进一步,你必须看到上面link中的Step 6: Codes for the arduino。它基本上是捕获传感器数据并将其作为 client.print( "GET /add.php?"); client.print("tempt1="); 附加到您的网站,以便您的 URL 变成类似 www.xyxy.com/add.php?tempt1=40 的东西,现在在这个 url www.xyxy.com/add.php?tempt1=40(在 add.php) 您可以使用 get 方法获取温度。

现在这里是您问题的主要答案。 在 Step 6: Codes for the arduino 给出的 function/library 中实现更多方法并扩展 void loop() 中的代码。做这样的事情 client.print("&&"); client.print("pressure"); client.print( pressure value ); // pressure value variable will have the pressure value from your inplementation.

因此您的最终 url 将类似于 http://www.xyxy.com/add.php?tempt1= temp_value&&pressure= pressure_value&& ..... other values in same format

现在在 add.php 中,您可以从 $temp = $_GET['tempt1'] 之类的 get 方法中捕获值,您可以使用它来插入 mysql 中。但请不要使用 mysql_query,而是使用准备好的语句。看这里 see this