我正在使用此域http://www.decathlon.commonarchitecture.ca/来托管我的phpmyadmin数据库和php代码。我想在串口监视器中读取数据库的特定列,一个接一个地显示每个数字。我不确定是使用GSM屏蔽,以太网屏蔽还是Arduino wifi屏蔽。这是我的PHP代码(缩进我不知道):
<?php
$dbhost = "mysql.commonarchitecture.ca";
$username = "arduinodb";
$password = "*******";
$db = "arduinodb" ;
mysql_connect("$dbhost" , "$username" , "$password");
//echo "Connected" ;
//select db
mysql_select_db($db);
//echo "Connected to db" ;
$sql="SELECT * FROM data";
$records=mysql_query($sql);
?>
<!DOCTYPE html>
<html>
<head>
<title> Consumption Data </title>
</head>
<body>
<table width="600" border="1" cellpadding="1" cellspacing"1">
<tr>
<th>Day</th>
<th>Date</th>
<th>Water Consumption (liters per person)</th>
<tr>
<?php
while($data=mysql_fetch_assoc($records)) {
echo "<tr>";
echo "<td>".$data['id']."</td>";
echo "<td>".$data['date']."</td>";
echo "<td>".$data['value']."</td>";
echo "</tr>";
}//end while
?>
</table>
</body>
</html>
代码有效,但是我不确定如何在Arduino上读取数据(对Arduino来说很新)
这是我的Arduino代码与以太网盾配对
#include <SPI.h>
#include <Ethernet.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192, 168, *, *);
EthernetClient client;
char server[] = "www.decathlon.commonarchitecture.ca";
void setup()
{
Serial.begin(9600);
// attempt a DHCP connection:
Serial.println("Attempting to get an IP address using DHCP:");
if (!Ethernet.begin(mac)) {
// if DHCP fails, start with a hard-coded address:
Serial.println("failed to get an IP address using DHCP, trying
manually");
Ethernet.begin(mac, ip);
}
Serial.print("My address:");
Serial.println(Ethernet.localIP());
}
void loop()
{
// connect to the server
if (client.connect(server, 80))
{
// print to serial monitor
Serial.println("connected...");
Serial.println("ARDUINO: forming HTTP request message");
// send data the server through GET request
client.print("GET /index.php?value");
client.println(" HTTP/1.1");
client.print("HOST: ");
client.println(server);
Serial.println("ARDUINO: HTTP message sent");
// give server time to receive request
delay(1000);
// get the response from the page and print it to serial port
// to ascertain that request was received properly
if(client.available())
{
Serial.println("ARDUINO: HTTP message received");
Serial.println("ARDUINO: printing received headers and
script response...\n");
while(client.available())
{
char c = client.read();
Serial.print(c);
}
}
else
{
Serial.println("ARDUINO: no response received / no response
received in time");
}
client.stop();
}
// do nothing forever after:
while(true);
}
我现在的问题是让Arduino读取我的php数据,我可以不使用http GET请求在我的串口监视器中显示数据吗?我正确使用此功能吗?有大量关于使用php / my s将Arduino传感器数据发布到Web上的文档,但没有那么多关于将设置数据检索回串行监视器的文档。这是监视器当前读取的内容......
Attempting to get an IP address using DHCP:
My address:192.168.*.*
connected...
ARDUINO: forming HTTP request message
ARDUINO: HTTP message sent
ARDUINO: no response received / no response received in time