I am new to arduino and PHP, I am trying to send rfid readings from the arduino uno with the ethernet shield(ENCJ28J60) to a PHP webpage. My first problem is I can’t get the rfid reading to actually display on the PHP webpage. Please see the attached arduino code and PHP code. I would really apprecaite any help or suggestions on this.
Thanks
Arduino Code
#include <Ethernet.h> //library for ethernet functions
#include <SPI.h>
#include <Dns.h>
#include <Client.h>
#include <SoftwareSerial.h> //library for client functions
SoftwareSerial RFID(2, 3); // RX and TX
// Ethernet settings
byte mac = {0x09,0xA2,0xDA,0x00,0x01,0x26}; //Replace with your Ethernet shield MAC
byte ip = { 192,168,0,54}; //The Arduino device IP address
byte subnet = { 255,255,255,0};
byte gateway = { 192,168,0,1};
IPAddress server(192,168,0,53); // IP-adress of server arduino sends data to
EthernetClient client;
bool connected = false;
int msg;
char newtag[14] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0}; // rfid tag value
//functions
void readTags()
{
if (RFID.available() > 0)
{
// read tag numbers
delay(100); // needed to allow time for the data to come in from the serial buffer.
for (int z = 0 ; z < 14 ; z++) // read the rest of the tag
{
int data1 = RFID.read();
newtag[z] = data1;
}
RFID.flush(); // stops multiple reads
}
}
void setup(void) {
Serial.begin(9600);
RFID.begin(9600);
Serial.println(“Initializing Ethernet.”);
delay(1000);
Ethernet.begin(mac);
}
void loop(void) {
if(!connected) {
Serial.println(“Not connected”);
if (client.connect(server, 80)) {
connected = true;
int RFID =analogRead(A1);
Serial.print(“RFID is “);
Serial.println(RFID);
Serial.println();
Serial.println(“Sending to Server: “);
client.print(“GET /formSubmit.php?t0=”);
Serial.print(“GET /formSubmit.php?t0=”);
client.print(RFID);
Serial.print(RFID);
client.println(” HTTP/1.1”);
Serial.println(” HTTP/1.1”);
client.println(“Host: http://localhost/PhpProject1/”);
Serial.println(“Host: http://localhost/PhpProject1/”);
client.println(“User-Agent: Arduino”);
Serial.println(“User-Agent: Arduino”);
client.println(“Accept: text/html”);
Serial.println(“Accept: text/html”);
//client.println(“Connection: close”);
//Serial.println(“Connection: close”);
client.println();
Serial.println();
delay(10000);
}
else{
Serial.println(“Cannot connect to Server”);
}
}
else {
delay(1000);
while (client.connected() && client.available()) {
char c = client.read();
Serial.print(c);
}
Serial.println();
client.stop();
connected = false;
}
}
sketch_dec03a.ino (3.23 KB)