我正在关注tweaking4all(https://www.tweaking4all.nl/hardware/arduino/arduino-ethernet-data-push/)的教程 我已经设置了我的sql数据库,并且有一个我正在运行php脚本的站点。当我手动输入将进入我的数据库的变量时,这样的http://apollonian-jacket.000webhostapp.com/add_data.php?serial=288884820500006X&temperature=12.3就可以了。数据将插入数据库中。现在我正在尝试用我的arduino做这个,但它不起作用。这就是我在串口监视器中看到的内容
Tweaking4All.com - Temperature Drone - v2.0
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
IP Address : 192.168.0.199
Subnet Mask : 255.255.255.0
Default Gateway IP: 192.168.0.1
DNS Server IP : 195.130.131.3
-> Connected
-> Connected
-> Connected
-> Connected
但是当我查看我的数据库时,我看不到任何变化
arduino的代码:
#include <Ethernet.h> // Used for Ethernet
// **** ETHERNET SETTING ****
// Arduino Uno pins: 10 = CS, 11 = MOSI, 12 = MISO, 13 = SCK
// Ethernet MAC address - must be unique on your network - MAC Reads T4A001 in hex (unique in your network)
byte mac[] = { 0x54, 0x34, 0x41, 0x30, 0x30, 0x31 };
// For the rest we use DHCP (IP address and such)
EthernetClient client;
char server[] = "www.apollonian-jacket.000webhostapp.com"; // IP Adres (or name) of server to dump data to
int interval = 5000; // Wait between dumps
void setup() {
Serial.begin(9600);
Ethernet.begin(mac);
Serial.println("Tweaking4All.com - Temperature Drone - v2.0");
Serial.println("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-\n");
Serial.print("IP Address : ");
Serial.println(Ethernet.localIP());
Serial.print("Subnet Mask : ");
Serial.println(Ethernet.subnetMask());
Serial.print("Default Gateway IP: ");
Serial.println(Ethernet.gatewayIP());
Serial.print("DNS Server IP : ");
Serial.println(Ethernet.dnsServerIP());
}
void loop() {
// if you get a connection, report back via serial:
if (client.connect(server, 80)) {
Serial.println("-> Connected");
// Make a HTTP request:
client.print( "GET /add_data.php?");
client.print("serial=");
client.print( "288884820500006X" );
client.print("&");
client.print("temperature=");
client.print( "12.3" );
client.println( " HTTP/1.1");
client.print( "Host: " );
client.println(server);
client.println( "Connection: close" );
client.println();
client.println();
client.stop();
}
else {
// you didn't get a connection to the server:
Serial.println("--> connection failed/n");
}
delay(interval);
}
我做了很多研究,但一切似乎都是正确的。在此先感谢!
答案 0 :(得分:0)
我注意到的第一件事是你正在使用&#34; www&#34;您的Ardunio代码中的子域名,但不是直接调用时的子域名。似乎www子域未正确映射,因为http://www.apollonian-jacket.000webhostapp.com/review_data.php似乎不起作用。