En gros j'ai fais deux codes le premier :
#include <SPI.h>
#include <Ethernet.h>
byte mac[] = { 0xA8, 0x61, 0x0A, 0xAE, 0x05, 0x2A };
EthernetClient client;
char* host = "archive.karibsen.fr";
void setup() {
Serial.begin(9600);
Serial.println("Starting Arduino");
if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DHCP");
while (true) {}
}
delay(2000);
Serial.println("Conecting...");
client.stop();
if (client.connect(host, 80)) {
Serial.println("-> Connected");
String url = "/assets/php/add.php?ID=AB2C6D8F";
client.print(String("GET ") + url + " HTTP/1.0\r\n" + "Host: " + host + "\r\n" + "User-Agent: ArduinoEthernet\r\n" + "Connection: close\r\n\r\n");
Serial.println("Stuff done");
while (client.connected()) {
String line = client.readStringUntil('\n');
Serial.println(line); //parse HTTP header
if (line == "\r") {
break;
}
}
if (client.available()) {
char c = client.read();
String ce = String(c);
if (ce.startsWith("none")) {
Serial.print("NN");
} else {
Serial.print(c);
}
}
}
else {
Serial.println("--> connection failed/n");
}
}
void loop() {
if (client.available()) {
char c = client.read();
String ce = String(c);
if (ce.startsWith("none")) {
Serial.print("NN");
} else {
Serial.print(c);
}
}
}
et le deuxieme
#include <Ethernet.h>
#include <SPI.h>
#include <MFRC522.h>
#define SS_PIN 9
#define RST_PIN 8
#define AccesFlag_PIN 2
#define Gate_PIN 3
#define Max_Acces 3
byte Count_acces=0;
byte CodeVerif=0;
byte Code_Acces[4]={0x67, 0xF3, 0x50, 0x39};
MFRC522 rfid(SS_PIN, RST_PIN); // Instance of the class
// Init array that will store new NUID
byte nuidPICC[4];
void setup()
{
// Init RS232
Serial.begin(9600);
// Init SPI bus
SPI.begin();
// Init MFRC522
rfid.PCD_Init();
// Init LEDs
pinMode(AccesFlag_PIN, OUTPUT);
pinMode(Gate_PIN, OUTPUT);
digitalWrite(AccesFlag_PIN, LOW);
digitalWrite(Gate_PIN, LOW);
}
void loop()
{
// Initialisé la boucle si aucun badge n'est présent
if ( !rfid.PICC_IsNewCardPresent())
return;
// Vérifier la présence d'un nouveau badge
if ( !rfid.PICC_ReadCardSerial())
return;
// Afffichage
Serial.println(("Un badge est détecté"));
// Enregistrer l’ID du badge (4 octets)
for (byte i = 0; i < 4; i++) {
nuidPICC[i] = rfid.uid.uidByte[i];
}
// Vérification du code
CodeVerif= GetAccesState(Code_Acces,nuidPICC);
if (CodeVerif!=1)
{
Count_acces+=1;
if(Count_acces==Max_Acces)
{
// Dépassement des tentatives (clignotement infinie)
while(1)
{
digitalWrite(AccesFlag_PIN, HIGH);
delay(1000);
digitalWrite(AccesFlag_PIN, LOW);
delay(1000);
digitalWrite(AccesFlag_PIN, HIGH);
delay(1000);
digitalWrite(AccesFlag_PIN, LOW);
delay(1000);
digitalWrite(AccesFlag_PIN, HIGH);
delay(1000);
digitalWrite(AccesFlag_PIN, LOW);
delay(1000);
digitalWrite(AccesFlag_PIN, HIGH);
delay(1000);
digitalWrite(AccesFlag_PIN, LOW);
delay(1000);
digitalWrite(AccesFlag_PIN, HIGH);
delay(1000);
digitalWrite(AccesFlag_PIN, LOW);
delay(1000);
// Affichage
Serial.println("Alerte!");
delay(1000);
asm("jmp 0x00");
}
}
else
{
// Affichage
Serial.println("Accès refusé");
// Un seul clignotement: Code erroné
digitalWrite(AccesFlag_PIN, HIGH);
delay(1000);
digitalWrite(AccesFlag_PIN, LOW);
}
}
else
{
// Affichage
Serial.println("Bonjour");
// Ouverture de la porte & Initialisation
digitalWrite(Gate_PIN, HIGH);
delay(1000);
digitalWrite(Gate_PIN, LOW);
Count_acces=0;
}
// Affichage de l'identifiant
Serial.println(" L'UID du tag est:");
for (byte i = 0; i < 4; i++)
{
Serial.print(nuidPICC[i], HEX);
Serial.print(" ");
}
Serial.println();
// Re-Init RFID
rfid.PICC_HaltA(); // Halt PICC
rfid.PCD_StopCrypto1(); // Stop encryption on PCD
}
byte GetAccesState(byte *CodeAcces,byte *NewCode)
{
byte StateAcces=0;
if ((CodeAcces[0]==NewCode[0])&&(CodeAcces[1]==NewCode[1])&&
(CodeAcces[2]==NewCode[2])&& (CodeAcces[3]==NewCode[3]))
return StateAcces=1;
else
return StateAcces=0;
}
J'aimerai que lorsque je passe une carte rfid cela me mette l'id, dans le lien qui me permet de me connecter au serveur