Bonjour,
je fait ce post car j'ai un soucis avec mon programme, le but de ce programme est de faire un historique des 10 dernières identifications à la borne RFID UM005 le tout sur une Arduino Uno.
Mon problème est le suivant: lorsque je passe plusieurs badges l'historique s'affiche bel et bien mais lorsque la page s'actualise (toutes les 2 secondes) l'historique est supprimé.
Je pense que cela est du au fait que les ids RFID ne sont pas stocker mais je ne trouve pas de moyen.
Voici mon code:
#include <SPI.h>
#include <Ethernet.h>
//Variables RFID
int bytesread = 0;
int val =0;
unsigned char code[11]; //Tableau qui contient toute la trame RFID
unsigned short calculated_crc;
// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,1,177);
// Initialize the Ethernet server library
// with the IP address and port you want to use
// (port 80 is default for HTTP):
EthernetServer server(80);
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
// start the Ethernet connection and the server:
Ethernet.begin(mac, ip);
server.begin();
Serial.print("server is at ");
Serial.println(Ethernet.localIP());
}
void loop() {
// listen for incoming clients
EthernetClient client = server.available();
if (client) {
Serial.println("Nouveau client");
// an http request ends with a blank line
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
Serial.write(c);
// if you've gotten to the end of the line (received a newline
// character) and the line is blank, the http request has ended,
// so you can send a reply
if (c == '\n' && currentLineIsBlank) {
// send a standard http response header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("Connection: close"); // the connection will be closed after completion of the response
client.println("Refresh: 2"); // refresh the page automatically every 2 sec
client.println();
client.println("<!DOCTYPE HTML>");
client.println("<html>");
client.print("Historique des idendifications :");
client.println("
");
// output the value of each analog input pin
for (int histId = 1; histId < 11; histId++) {
client.print(histId);
client.println(" ");
//RFID
if(Serial.available()>0){//Si des données sont présentes sur le port série
bytesread = 0;
while(bytesread<11)
{
if( Serial.available()>0)
{
val = Serial.read();
code[bytesread] = val; //Rentre la valeur de chaque octet dans un tableau
bytesread++;
}
}
}
CRC2(code,&calculated_crc,9);// Appel de la fonction qui calcule le CRC (voir datashett UM005)
boolean a_card = true;
if(bytesread != 0){
if( (calculated_crc>>8)==code[9] && (calculated_crc&0x00FF) == code[10]){
Serial.print("Id:");
for(int i=3;i<8;i++) // Lecture à partir du 3éme octet jusqu'au 7éme octet
{
Serial.print(code[i],HEX); //Rentre dans un tableau l'Id du badge RFID
client.print(code[i],HEX);
}
Serial.println("");//Retour à la ligne
bytesread = 0;
}
}
//Fin Rfid
client.println("
");
}
client.println("</html>");
break;
}
if (c == '\n') {
// you're starting a new line
currentLineIsBlank = true;
}
else if (c != '\r') {
// you've gotten a character on the current line
currentLineIsBlank = false;
}
}
}
// give the web browser time to receive the data
delay(1);
// close the connection:
client.stop();
Serial.println("client disonnected");
}
}
// Fonction qui calcule le CRC
void CRC2(unsigned char * Data, unsigned short * CRC, unsigned char Bytes){
int i, byte;
unsigned short C;
*CRC = 0x0000;
for (byte = 1; byte <= Bytes; byte ++, Data ++)
{
C = ((*CRC >> 8) ^ *Data) << 8;
for (i = 0; i < 8; i ++)
{
if (C & 0x8000)C = (C << 1) ^ 0x1021;
else C = C << 1;
}
*CRC = C^(*CRC << 8);
}
}