Arduino uno + ethernet shield+rfid rc522

Hi,
I am facing difficulty in the code for the above mentioned project topic .The problem statement is - I need to read data from RFID then send it to a web page through Ethernet ,whenever the card is read it should be stored on the web page ( irrespective of user accessing the web page) but when the user access the page he should get the details of which cards have been read
Thank you

Post your code.

#include<String.h>
#include<SPI.h>
#include<Ethernet.h>
#include <MFRC522.h>

#define RST_PIN 8 // Configurable, see typical pin layout
#define SS_PIN 9 // Configurable, see typical pin layout

MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance

/************************ DATA PERTAINING TO ETHERNET *********************************/

//details obtained from cmd>ipconfig /all

byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED}; //set a unique MAC ID for the server.
byte ip[] = {192, 168, 0, 3}; //open IP port address
byte subnet[] = {255, 255, 255, 0}; //default subnet mask
byte gateway[] = {192, 168, 0, 1}; //default gateway
String x = "";
String y = "";
EthernetServer server(80);

/************************ DATA PERTAINING TO RFID TAGS *********************************/

byte card[] = {0x39, 0xB5, 0xB2, 0x65}; //already known
byte tag[] = {0xB6, 0x73, 0xF3, 0x30}; //already known
byte RFID_in[] = {0, 0, 0, 0};
int flag = 0;

/***************************************************************************************/

void setup()
{
Serial.begin(115200);
while (!Serial); // Do nothing if no serial port is opened (added for Arduinos based on ATMEGA32U4)
SPI.begin(); // Init SPI bus
mfrc522.PCD_Init(); // Init MFRC522
mfrc522.PCD_DumpVersionToSerial(); // Show details of PCD - MFRC522 Card Reader details

Serial.println(F("Scan PICC to see UID, SAK, type, and data blocks..."));

Ethernet.begin(mac, ip, gateway, subnet); //Start Ethernet Shield
x = "";
flag = 0;
}

void loop()
{
// Look for new cards
if ( ! mfrc522.PICC_IsNewCardPresent())
{
return;
}

// Select one of the cards
if ( ! mfrc522.PICC_ReadCardSerial())
{
return;
}

//Store card ID number into memory for verification

for (int i = 0; i < mfrc522.uid.size; i++)
{
RFID_in = (mfrc522.uid.uidByte*);*
* }*
* //check each byte of card id*
* if (RFID_in[0] == card[0] && RFID_in[1] == card[1] && RFID_in[2] == card[2] && RFID_in[3] == card[3] && (flag != 1))
_
{_
_
flag = 1;_
_
Serial.println();_
_
Serial.println("CARD FOUND");_
_
}_
_
//check each byte of card id*_
* else if (RFID_in[0] == tag[0] && RFID_in[1] == tag[1] && RFID_in[2] == tag[2] && RFID_in[3] == tag[3] && (flag != 2))
_
{_
_
flag = 2;_
_
Serial.println();_
_
Serial.println("TAG FOUND");_
_
}_
_ /*********************** START SEREVER AND WEBPAGE /_
_
while (!flag)
_
_
{
_
_
EthernetClient client = server.available();
_
_
if (client)
_
_
{
_
_
Serial.println("Are u requesting service?");
_
_
while (client.connected())
_
_
{
_
_
if (client.available())
_
_
{
_
_
char c = client.read();
_
_
x.concat(c);
_
_
if (c == '\n')
_
_
{
_
_
Serial.print(x);
_
_
client.println("HTTP/1.1 200 OK");
_
_
client.println("Content-Type:text/html");_
_
client.println();_
_
client.println("RFID DATA");*_

* client.stop();*
* }*
* }*
* }*
* }*
* }*
* if (flag)*
* {*
* EthernetClient client = server.available();*
* if (client)*
* {*
* Serial.println("Service is being requested...");*
* while (client.connected())*
* {*
* if (client.available())*
* {*
* char c = client.read();*
* x.concat(c);*
* if (c == '\n')*
* {*
* if (flag > 0)*
* {*
* switch (flag)*
* {*
* case 1: y.concat("You scanned a card*
"); break;
* case 2: y.concat("You scanned a tag*
"); break;
* }*
* Serial.print(x);*
* client.println("HTTP/1.1 200 OK");*
* client.println("Content-Type:text/html");*
* client.println();*

_ /********** REFRESH PAGE EVERY SECOND ****************/_

* client.print("");*
* client.print("<meta http-equiv="refresh" content="1">");*
* client.print("RFID DATA");*
* client.print("");*
_ /*****************************/_
* client.println("" + y + "");*
* client.stop();*
* }*
* }*
* }*
* }*
* }*
* }*
}

Hi to all. I'm working with the OP on this project. The problem actually are as follows

  1. WEB PAGE LOADS ONLY AFTER the 1st id is detected. Then the page is set to refresh every second and prints whatever is detected at the next refresh. What we want is, initially, load a blank page and print data as different IDs get scanned

  2. After a certain number of consecutive prints, page goes blank but still the page reloads as long as a tag is in the range of the antenna. Is the y.concat() depleting arduino's memory or what?

Code is as below.

#include<String.h>
#include<SPI.h>
#include<Ethernet.h>
#include <MFRC522.h>

#define RST_PIN         8         // Configurable, see typical pin layout
#define SS_PIN          9         // Configurable, see typical pin layout

MFRC522 mfrc522(SS_PIN, RST_PIN);  // Create MFRC522 instance

/************************ DATA PERTAINING TO ETHERNET *********************************/

//details obtained from cmd>ipconfig /all

byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED}; //set a unique MAC ID for the server.
byte ip[] = {192, 168, 0, 3}; //open IP port address
byte subnet[] = {255, 255, 255, 0}; //default subnet mask
byte gateway[] = {192, 168, 0, 1};  //default gateway
String x = "";
String y = "";
EthernetServer server(80);

/************************ DATA PERTAINING TO RFID TAGS *********************************/

byte card[] = {0x39, 0xB5, 0xB2, 0x65};   //already known
byte tag[] = {0xB6, 0x73, 0xF3, 0x30};    //already known
byte RFID_in[] = {0, 0, 0, 0};
int flag = 0;

/***************************************************************************************/

void setup()
{
  Serial.begin(115200);
  while (!Serial);                    // Do nothing if no serial port is opened (added for Arduinos based on ATMEGA32U4)
  SPI.begin();                        // Init SPI bus
  mfrc522.PCD_Init();                 // Init MFRC522
  mfrc522.PCD_DumpVersionToSerial();  // Show details of PCD - MFRC522 Card Reader details

  Serial.println(F("Scan PICC to see UID, SAK, type, and data blocks..."));

  Ethernet.begin(mac, ip, gateway, subnet); //Start Ethernet Shield
  x = "";
  flag = 0;
}

void loop()
{
  // Look for new cards
  if ( ! mfrc522.PICC_IsNewCardPresent())
  {
    return;
  }

  // Select one of the cards
  if ( ! mfrc522.PICC_ReadCardSerial())
  {
    return;
  }

  //Store card ID number into memory for verification

  for (int i = 0; i < mfrc522.uid.size; i++)
  {
    RFID_in[i] = (mfrc522.uid.uidByte[i]);
  }

  //check each byte of card id
  if (RFID_in[0] == card[0] && RFID_in[1] == card[1] && RFID_in[2] == card[2] && RFID_in[3] == card[3] && (flag != 1))
  {
    flag = 1;
    Serial.println();
    Serial.println("CARD FOUND");
  }

  //check each byte of card id
  else if (RFID_in[0] == tag[0] && RFID_in[1] == tag[1] && RFID_in[2] == tag[2] && RFID_in[3] == tag[3] && (flag != 2))
  {
    flag = 2;
    Serial.println();
    Serial.println("TAG FOUND");
  }

  /************************ START SEREVER AND WEBPAGE *********************************/

  while (!flag)
  {
    EthernetClient client = server.available();
    if (client)
    {
      Serial.println("Are u requesting service?");
      while (client.connected())
      {
        if (client.available())
        {
          char c = client.read();
          x.concat(c);
          if (c == '\n')
          {
            Serial.print(x);
            client.println("HTTP/1.1 200 OK");
            client.println("Content-Type:text/html");
            client.println();

            client.println("<head><title>RFID DATA</title></head>");
            //client.println("<body><p><a href='/?Led=1'>Turn LED on</a></p><p><a href='/?Led=0'>Turn LED off</a></p></body>");
            client.stop();
          }
        }
      }
    }
  }

  if (flag)
  {
    EthernetClient client = server.available();
    if (client)
    {
      Serial.println("Service is being requested...");
      while (client.connected())
      {
        if (client.available())
        {
          char c = client.read();
          x.concat(c);
          if (c == '\n')
          {
            if (flag > 0)
            {
              switch (flag)
              {
                case 1: y.concat("You scanned a card
"); break;
                case 2: y.concat("You scanned a tag 
"); break;
              }

              Serial.print(x);

              client.println("HTTP/1.1 200 OK");
              client.println("Content-Type:text/html");
              client.println();
              
              /*************** REFRESH PAGE EVERY SECOND ****************/
              
              client.print("<HEAD>");
              client.print("<meta http-equiv=\"refresh\" content=\"1\">");
              client.print("<TITLE />RFID DATA</title>");
              client.print("</head>");

              /**********************************************************/
              client.println("<body>" + y + "</body>");
              client.stop();
            }
          }
        }
      }
    }
  }
}
String x = "";
String y = "";

I'm not going to pull any punches. These are stupid names for global variables. Either they should not be global, or they need better names.

Even better would be to get over your need for crutches. Learn to use strings.

void loop()
{
  // Look for new cards
  if ( ! mfrc522.PICC_IsNewCardPresent())
  {
    return;
  }

If there is not a card present, do ABSOLUTELY nothing. Ever. Well, THAT is why you have problem #1.

//Store card ID number into memory for verification

  for (int i = 0; i < mfrc522.uid.size; i++)
  {
    RFID_in[i] = (mfrc522.uid.uidByte[i]);
  }

It is NOT necessary to copy the data "for verification".

  if (RFID_in[0] == card[0] && RFID_in[1] == card[1] && RFID_in[2] == card[2] && RFID_in[3] == card[3]

Ever heard of memcmp()? It's time you learned about it, then.

    Serial.println("CARD FOUND");

Forget something? Like the F() macro?

  while (!flag)

WTF? Why does responding to a client request depend on a valid tag having been scanned?

What you reply to the client might depend on a card having been scanned, but replying at all does not.

Why is it necessary to keep adding what the client asked for to the same String, when you are going to provide EXACTLY the same response regardless of what the client asked for? Can you imagine google doing that?

You: Hey, google, I want to find an axle bearing for a 65 Ford Falcon.
Google: Here's a list of sites selling roses for less than $1 each.

You: Hey, what does that have to do with axle bearings?
Google: Here's a list of sites selling roses for less than $1 each.

Neither of your uses of the resource-wasting String class is necessary.

Thank you very much sir for your guidance it had helped me alot