i cannot obtain an ip address from my router that is responsible for connecting to the php code and connecting to the sql database (im using xampp and phpmyadmin)
it displays this in the serial moni:
0.0.0.0
CLEARDATA
LABEL,Date,Time,RFID UID,Name
Scan PICC to see UID...
this is my arduino sketch:
#include <SPI.h>
#include <MFRC522.h>
#include <Ethernet.h>
#define SS_PIN 10
#define RST_PIN 9
MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance.
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; // Ethernet shield MAC address
char server[] = "192.168.1.8"; // IP address Komputer
IPAddress ip(192,168,1,8); // IP address Ethernet Shield
// the dns server ip
IPAddress dnServer(192, 168, 1, 1);
// the router's gateway address:
IPAddress gateway(192, 168, 1, 1);
// the subnet:
IPAddress subnet(255, 255, 255, 0);
EthernetClient client;
int buzz = 2;
int readsuccess;
byte readcard[4];
char str[32] = "";
String StrUID;
struct CardMapping {
String uid;
String name;
};
const int NUM_MAPPINGS = 3; // Adjust this based on the number of stored mappings
CardMapping mappings[NUM_MAPPINGS] = {
{"B3AD08A8", "Tristan Caponpon"},
{"43E569A6", "Anton Leonard"},
{"YOUR_STORED_UID_3", "Name3"}
};
void setup() {
pinMode(buzz, OUTPUT);
Serial.begin(9600); // Initialize serial communications with the PC
SPI.begin(); // Init SPI bus
mfrc522.PCD_Init(); // Init MFRC522 card
Ethernet.begin(mac, ip, dnServer, gateway, subnet);
Serial.println(Ethernet.localIP());
delay(1000);
Serial.println("CLEARDATA");
Serial.println("LABEL,Date,Time,RFID UID,Name");
delay(1000);
Serial.println("Scan PICC to see UID...");
Serial.println("");
}
void loop() {
readsuccess = getid();
if (readsuccess) {
String name = getNameFromUID(StrUID);
Serial.println((String) "DATA,DATE,TIME," + StrUID + "," + name);
digitalWrite(buzz, HIGH);
delay(100);
digitalWrite(buzz, LOW);
sendDataToServer(StrUID, name);
}
}
int getid() {
if (!mfrc522.PICC_IsNewCardPresent()) {
return 0;
}
if (!mfrc522.PICC_ReadCardSerial()) {
return 0;
}
Serial.println("THE UID OF THE SCANNED CARD IS:");
for (int i = 0; i < 4; i++) {
readcard[i] = mfrc522.uid.uidByte[i]; // storing the UID of the tag in readcard
array_to_string(readcard, 4, str);
StrUID = str;
}
mfrc522.PICC_HaltA();
return 1;
}
void array_to_string(byte array[], unsigned int len, char buffer[]) {
for (unsigned int i = 0; i < len; i++) {
byte nib1 = (array[i] >> 4) & 0x0F;
byte nib2 = (array[i] >> 0) & 0x0F;
buffer[i * 2 + 0] = nib1 < 0xA ? '0' + nib1 : 'A' + nib1 - 0xA;
buffer[i * 2 + 1] = nib2 < 0xA ? '0' + nib2 : 'A' + nib2 - 0xA;
}
buffer[len * 2] = '\0';
}
String getNameFromUID(String uid) {
for (int i = 0; i < NUM_MAPPINGS; i++) {
if (mappings[i].uid == uid) {
return mappings[i].name;
}
}
return "Unknown";
}
void sendDataToServer(String uid, String name) {
if (client.connect(server, 80)) {
Serial.println("Connected to server");
// Construct the URL with both parameters
String url = "/host_php.php?uid=" + uid + "&name=" + name;
// Send the HTTP GET request
client.println("GET " + url + " HTTP/1.1");
client.println("Host: localhost");
client.println("Connection: close");
client.println();
} else {
Serial.println("Connection failed");
}
delay(1000);
}
its for my capstone project i need your help guys thank youu