我正在使用基于 rfid 的 arduino 构建电子收费系统;我想将标签的“唯一 ID”(由 arduino 读取)发送到 php 脚本(存储在本地 apache 服务器根文件夹中)。我已经编写了代码,请指出找出错误并查看以太网设置在程序中是否正确..
#include <SPI.h>
#include <Ethernet.h>
EthernetServer server(80);
byte mac[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
IPAddress gateway(192,168,1,1);
IPAddress subnet(255,255,255,0);
IPAddress ip(192,168,1,4);
EthernetClient client;
int val = 0;
char code[10];
int bytesread = 0;
void setup()
{
Ethernet.begin(mac, ip, gateway, subnet);
Serial.begin(9600);
pinMode(2,OUTPUT);
digitalWrite(2, HIGH);
}
void loop() <br>
{
if(Serial.available() > 0) {
if((val = Serial.read()) == 10) {
bytesread = 0;
while(bytesread<10) {
if( Serial.available() > 0) {
val = Serial.read();
if((val == 10)||(val == 13)) {
break;
}
code[bytesread] = val;
bytesread++;
}
}
if(bytesread == 10) {
client.print("GET try.php?code=");
client.print(code);
client.println(" HTTP/1.1");
client.println("Host: localhost");
client.println();
}
bytesread = 0; <br>
digitalWrite(2, LOW);
delay(1500);
digitalWrite(2, HIGH); // Activate the RFID reader
}
}
}
the php script:
<?php
$variable = $_GET['code']
echo "code is $variable ";
?>