我正在構建一個簡單的應用程序,我想從我的Arduino使用enc28j60發送GET請求到位於我的在線主機中的php腳本。除了從數據庫中看不到任何東西外,一切看起來都很完美。使用enc28j60無法發送GET請求arduino使用enc28j60
引腳:
ENC SO - > Arduino的銷12
ENC SI - > Arduino的銷11
ENC SCK - > Arduino的銷13
ENC CS - > Arduino的銷10
ENC VCC - >的Arduino 3V3銷
ENC GND - >甲rduino GND引腳
這裏是Arduino的代碼:
#include <EtherCard.h>
#define PATH "index.php"
#define VARIABLE "test"
// ethernet interface mac address, must be unique on the LAN
byte mymac[] = { 0x74,0x69,0x69,0x2D,0x30,0x31 };
const char website[] PROGMEM = "billyval-com.stackstaging.com";
byte Ethernet::buffer[700];
uint32_t timer;
Stash stash;
void setup() {
Serial.begin(57600);
Serial.println("\n[webClient]");
if (ether.begin(sizeof Ethernet::buffer, mymac) == 0)
Serial.println("Failed to access Ethernet controller");
if (!ether.dhcpSetup())
Serial.println("DHCP failed");
ether.printIp("IP: ", ether.myip);
ether.printIp("GW: ", ether.gwip);
ether.printIp("DNS: ", ether.dnsip);
if (!ether.dnsLookup(website))
Serial.println("DNS failed");
ether.printIp("SRV: ", ether.hisip);
}
void loop() {
ether.packetLoop(ether.packetReceive());
if (millis() > timer) {
timer = millis() + 10000;
byte sd = stash.create();
stash.print("variable=");
stash.print(VARIABLE);
stash.save();
Stash::prepare(PSTR("GET http://$F/$F HTTP/1.1" "\r\n"
"Host: $F" "\r\n"
"Content-Length: $D" "\r\n"
"Content-Type: application/x-www-form-urlencoded; charset=UTF-8" "\r\n"
"\r\n"
"$H"),
website, PSTR(PATH), website, stash.size(), sd);
// send the packet - this also releases all stash buffers once done
ether.tcpSend();
}
}
,這裏是基本的PHP腳本:
<?php
$link = mysqli_connect("xxxx", "xxx", "xxx", "xxx");
if(mysqli_connect_error()){
die("database failed");
}
if(isset($_GET['variable'])){
$query = "INSERT INTO variables (variable) VALUES ('". $_GET['variable'] ."') ";
mysqli_query($link, $query);
}
?>
這裏是我從串口監視器採取:
[Web客戶端]
IP:192.168.10.10
GW:XXX
DNS:XXX
SRV:XXX
然而,當我檢查的基礎我看不到任何東西插入。但是,如果我在瀏覽器中手動執行此操作,例如: billyval-com.stackstaging.com/index.php?variable=x我可以在數據庫中看到插入的值(x)。 我改變了發佈,但我不能看到任何改變。
我無法弄清楚問題出在哪裏,如果有人能幫助我,我會在這裏發佈。
非常感謝。
GET HTTP請求應該沒有消息體。 –
你可以更特別嗎?我認爲我必須從Stash :: prepare中刪除一些東西? – kakavia
https://www.w3schools.com/tags/ref_httpmethods.asp –