I am building electronic toll colection system using arduino which rfid based;i want to send the “unique id” of the tag(read by arduino) to php script(stored on local apache server root folder).i have written the code please point out the mistakes and also have a look on the ethernet settings whether they are correct in the program..
#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 ";
?>
Seems you’re missing a “client.connect(…)” to connect to your PHP server before sending it an HTTP request :
http://arduino.cc/en/Reference/EthernetClient