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 ";
?>