Based on a post at the Arduino Ethernet topic (link);
Thanks for you answer.
By the way i managed to connect and push data to server. All thanks to your project.
As you know i’m trying to push RFID card data to MYSQL server.And i’m testing it 2 cards.
But i had a problem again.When i try to push first data it won’t work.After first try it sends data.But the again one more problem is when i change the card it sends same information and after it sends changed card data.
————add_data.php————–
<?php
include (‘dbconnect.php’);
$sql_insert = “INSERT INTO test.myguests (firstname, card_id, lastname) VALUES (‘”.$_GET[“firstname”].”‘, ‘”.$_GET[“card_id”].”‘, ‘”.$_GET[“lastname”].”‘)”;
if(mysqli_query($con,$sql_insert))
{
echo “Done”;
mysqli_close($con);
}
else
{
echo “error is “.mysqli_error($con );
}
?>
by the way i have to tell that RFID reader and ENC28J60 are using same ports(50,51,52).And i’m controlling them using RFID SDA pin,ENC28J60’s CS pin.
and here is my arduino code:
#include <SPI.h>
#include <MFRC522.h>
#include <UIPEthernet.h> // Used for Ethernet
#include <LiquidCrystal.h>
#define SS_PIN 20
#define RST_PIN 2
MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance.
// * ETHERNET SETTING *
// Ethernet MAC address – must be unique on your network – MAC Reads T4A001 in hex (unique in your network)
static byte mac[] = { 0x54, 0x34, 0x41, 0x30, 0x30, 0x31 };
// For the rest we use DHCP (IP address and such)
EthernetClient client;
char server[] = “192.168.0.105”; // IP Adres (or name) of server to dump data to
int interval = 5000; // Wait between dumps
LiquidCrystal lcd(22, 23, 4, 5, 6, 7);
void setup()
{
SPI.begin();// Initiate SPI bus
mfrc522.PCD_Init(); // Initiate MFRC522
lcd.begin(16, 2);
lcd.setCursor(0, 0);
lcd.print(“eAttendance v1.0”);
lcd.setCursor(0, 1);
lcd.print(“Connecting…”);
pinMode(20, OUTPUT);
pinMode(53, OUTPUT);
digitalWrite(53, LOW);
digitalWrite(20, HIGH);
Serial.begin(9600); // Initiate a serial communication
Ethernet.begin(mac);
Serial.println(“eAttendace System v1.0”);
Serial.println(“—————————————–\n”);
Serial.print(“IP Address : “);
Serial.println(Ethernet.localIP());
Serial.print(“Subnet Mask : “);
Serial.println(Ethernet.subnetMask());
Serial.print(“Default Gateway IP: “);
Serial.println(Ethernet.gatewayIP());
Serial.print(“DNS Server IP : “);
Serial.println(Ethernet.dnsServerIP());
Serial.println(“Approximate your card to the reader…”);
Serial.println();
}
void loop()
{
lcd.setCursor(0, 0);
lcd.print(“eAttendance v1.0”);
lcd.setCursor(0, 1);
lcd.print(“Waiting card…”);
digitalWrite(53, HIGH);
digitalWrite(20, LOW);
// Look for new cards
if ( ! mfrc522.PICC_IsNewCardPresent())
{
return;
}
// Select one of the cards
if ( ! mfrc522.PICC_ReadCardSerial())
{
return;
}
//Show UID on serial monitor
Serial.print(“UID tag :”);
String content = “”;
byte letter;
for (byte i = 0; i < mfrc522.uid.size; i++)
{
Serial.print(mfrc522.uid.uidByte < 0x10 ? ” 0″ : ” “);
Serial.print(mfrc522.uid.uidByte, HEX);
content.concat(String(mfrc522.uid.uidByte < 0x10 ? ” 0″ : ” “));
content.concat(String(mfrc522.uid.uidByte, HEX));
}
Serial.println();
Serial.print(“Message : “);
content.toUpperCase();
if (content.substring(1) == “C2 E7 BC 50”) //change here the UID of the card/cards that you want to give access
{
// if you get a connection, report back via serial
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(“Sendind…”);
lcd.setCursor(0, 1);
lcd.print(“ID:C2-E7-BC-50”);
digitalWrite(53, LOW);
digitalWrite(20, HIGH);
if (client.connect(server, 80)) {
Serial.println(“-> Connected”);
// Make a HTTP request:
client.print( “GET /card/add_data.php?”);
client.print(“firstname=”);
client.print( “Gerelsukh” );
client.print(“&&”);
client.print(“card_id=”);
client.print( “C2E7BC50” );
client.print(“&&”);
client.print(“lastname=”);
client.print( “Tsogtgerel” );
client.println( ” HTTP/1.1″);
client.print( “Host: ” );
client.println(server);
client.println( “Connection: close” );
client.println();
client.println();
Serial.println(“Writed”);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(“Data Sent!”);
client.stop();
}
else {
// you didn’t get a connection to the server:
Serial.println(“–> connection failed/n”);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(“No Connection!”);
}
}
else if (content.substring(1) == “7A 8F 74 63”) //change here the UID of the card/cards that you want to give access
{
// if you get a connection, report back via serial:
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(“Sendind…”);
lcd.setCursor(0, 1);
lcd.print(“ID:7A-8F-74-63”);
digitalWrite(53, LOW);
digitalWrite(20, HIGH);
client.connect(server, 80);
if (client.connect(server, 80)) {
Serial.println(“-> Connected”);
// Make a HTTP request:
client.print( “GET /card/add_data.php?”);
client.print(“firstname=”);
client.print( “Gombo” );
client.print(“&&”);
client.print(“card_id=”);
client.print( “7A8F7463” );
client.print(“&&”);
client.print(“lastname=”);
client.print( “Khorloo” );
client.println( ” HTTP/1.1″);
client.print( “Host: ” );
client.println(server);
client.println( “Connection: close” );
client.println();
client.println();
Serial.println(“Writed”);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(“Data Sent!”);
client.stop();
}
else {
// you didn’t get a connection to the server:
Serial.println(“–> connection failed/n”);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(“No Connection!”);
}
delay(interval);
}
else {
Serial.println(“Unregistered User”);
delay(3000);
}
digitalWrite(53, HIGH);
digitalWrite(20, LOW);
}
any advices will be appreciated.