我想要详细的一步一步的过程和代码,如何将温度传感器,压力传感器,包含时间戳的湿度传感器集成到数据库中的单个表中。我希望每隔15分钟将这些值放入MySQL数据库。
答案 0 :(得分:0)
这是教程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 ;
进一步展开,您必须在上面的链接中看到Step 6: Codes for the arduino
。它基本上捕获传感器数据并将其作为client.print( "GET /add.php?");
client.print("tempt1=");
附加到您的网站,以便您的网址变为www.xyxy.com/add.php?tempt1=40
,现在可以使用此网址www.xyxy.com/add.php?tempt1=40
(在add.php上)获得温度的方法。
现在,这是您问题的主要答案。
在Step 6: Codes for the arduino
中给出的函数/库中实现更多方法,并在void loop()
内扩展代码。做这样的事情client.print("&&");
client.print("pressure");
client.print( pressure value ); // pressure value variable will have the pressure value from your inplementation
。
因此,您的最终网址将类似于http://www.xyxy.com/add.php?tempt1= temp_value&&pressure= pressure_value&& ..... other values in same format
。
现在在add.php
中,您可以从get $temp = $_GET['tempt1']
这样的get方法中捕获值,并且可以使用它在mysql中插入。但请不要使用mysql_query
,而是使用预准备语句。见see this