Wifi connected RFID Reader

Hi Community,

I have a Wifi-Module "ESP8266" connected to a RFID reader. Data Structure (Serial ASCII)

I want to read out the ID of the RFID-Tag.
The ID is then sent to a Website.
Data of this RFID-Tag should look like this "010D68F03C". It should be 10 characters long.

If i´m using the code below i get for "TagData" --> "3fa6e6e6991ee63e32f2cad6f20"

String TagData;
while(Serial.available() > 0) 
{
    byte incomingData = Serial.read();
    TagData = TagData + String(incomingData, HEX);
}

By using the code below i get for "TagData" --> "631662302301533023062502422022142420"

String TagData;
while(Serial.available() > 0) 
{
    byte incomingData = Serial.read();
    TagData = TagData + String(incomingData);
}

I really have no idea how to convert to this 10 character long format.
Hopefully someone can help me.

You could use (for the concatenation)

    TagData = TagData + (char)incomingData;

Your algorithm does not check content or length.

Thanks for your code sharing.

while(Serial.available() > 0) 
{
    byte incomingData = Serial.read();
    TagData = TagData + char(incomingData);
}

With your code i get for "TagData" --> "?¦ææ™æ>2òÊÖò´"
So not the wanted 10 characters "010D68F03C"

For sending the data to my website i use this function:

void sendRFIDReaderData()
{
  client.flush(); // Discard any bytes that have been written to the client but not yet read
  String s = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n<!DOCTYPE HTML>\r\n<html>\r\n<strong>RFID-TAG Data:</strong> "; // Prepare the response
  s += TagData + "
";
  s += "</html>\n";
  client.print(s); // Send the response to the client
  delay(1);
  Serial.println("Client disonnected"); // The client will actually be disconnected. When the function returns and 'client' object is detroyed
}

If i´m using the code below i get for "TagData" --> "3fa6e6e6991ee63e32f2cad6f20"

Why would you be using that mess? Converting the ASCII value of the character to a String in HEX format makes no sense.

Your right i can see it makes absolutely no sense to convert into a HEX format.
But i really don´t now how to convert that i get a format for this --> "010D68F03C"
Can somebode share a code example?

Can somebode share a code example?

To convert some data that you haven't a clue as to its format to something else that makes no sense either?

Print the raw value that you are reading from the RFID reader in base 10 with identification and spacing between the values.

Explain WHY you think that the raw data is supposed to map to "010D68F03C".

Explain WHY you think you need that AS A STRING.

THEN, we can get somewhere.

Right now i have my RFID-Reader connected to a Tibbo WLAN to Serial converter.
The Tibbo gives a COM-port on which i can connect with a terminal program.
When i swipe a RFID Tag over the reader i get "010D68F03C" back from the Tibbo COM-port.

When im hooking up the Reader-Data-Output to my ESP8266 with the code below i get:
--> "631662302301533023062502422022142420"
HEX: 36 33 31 36 36 32 33 30 32 33 30 32 30 33 35 30 32 30 34 34 36 33 38 33 38 34 31 32 31 34 32 34 32 30
DECIMAL: 054 051 049 054 054 050 051 048 050 051 048 050 048 051 053 048 050 048 052 052 054 051 056 051 056 052 049 050 049 052 050 052 050 048

String TagData;
while(Serial.available() > 0) 
{
    byte incomingData = Serial.read();
    TagData = TagData + String(incomingData);
}

Any suggestions would help?

I attached the Data that i get from the Tibbo Serial-Wifi Converter "010D68F03C".
And the data from my ESP8266. "631662302301533023062502422022142420"
Any idea how to convert RFID data?

When im hooking up the Reader-Data-Output to my ESP8266 with the code below i get:

You don't KNOW anything about how that stream of data maps to ANYTHING. Quit ASSuming that you do. QUITPRINTINGTHEVALUESJAMMEDUPAGAINSTEACHOTHER.

When you do that, you have no clue where one value ends and the next begins. Therefore, you can not make ANY assumptions about where one single value is in that stream of characters.

You are ASSuming that each byte read from the RFID reader prints out as one digit in that stream. That is a completle incorrect ASSumption.

You are ASSuming that you need to add 0x30 to each value. Can I have some of what you're smoking?

Try again.

You are ASSuming that each byte read from the RFID reader prints out as one digit in that stream. That is a completle incorrect ASSumption.

What is the correct assumption then?
Regarding to the reader data format i should get at the start an STX (0x02).
At the end i should get an ETX (0x03).
But i dont even get that in my stream. I´m a little stuck.

What is the correct assumption then?

The assumption is that you will post ALL of your code.
The assumption is that you will read and implement the suggestions made here.

Until then, you are just blowing smoke.

PaulS:
Why would you be using that mess? Converting the ASCII value of the character to a String in HEX format makes no sense.

Other way around i suspect.

Standard Wiegand readers output a hex string.

PaulS:
You are ASSuming that each byte read from the RFID reader prints out as one digit in that stream. That is a completle incorrect ASSumption.

Try again.

Hex is output as pairs of digits.

Hex is output as pairs of digits.

How many digits are output when the value is 4? Do NOT assume that the output will be 04!

dawinci:
I attached the Data that i get from the Tibbo Serial-Wifi Converter "010D68F03C".
And the data from my ESP8266. "631662302301533023062502422022142420"
Any idea how to convert RFID data?

Are you by any chance feeding weigand directly into the rs232 port of the transmitter ?

Looking at post 6 that would indeed seem to be the case.

The format that i should get from the Reader is as an attachment .jpg in my first post.
Well here is my code i want to share with you.
Thanks for the great support in the forum for beginners like me.

#include <ESP8266WiFi.h>
#include <SoftwareSerial.h>

const char ssid[] = "MySSID";
const char password[] = "MYPassword";
const char http_site[] = "www.URL.com";
const int http_port = 80;

WiFiServer server(80);
WiFiClient client;
SoftwareSerial readerSerial(5, SW_SERIAL_UNUSED_PIN); // RX, TX

#define pinSwitch1 14 // Switch1
#define pinSwitch2 12 // Switch2
#define pinSwitch3 13 // Switch3
#define pinSwitch4 15 // Switch4
byte valueSwitch1; // is Switch1 On(1) or Off(0) ?
byte valueSwitch2;
byte valueSwitch3;
byte valueSwitch4;

unsigned long startMillis1 = 0;   // startTime when Switch1 is activated
unsigned long startMillis2 = 0;
unsigned long startMillis3 = 0;
unsigned long startMillis4 = 0;
unsigned long enableTimeSwitch1 = 0;
unsigned long enableTimeSwitch2 = 0;
unsigned long enableTimeSwitch3 = 0;
unsigned long enableTimeSwitch4 = 0;

String TagData;
int incomingData;

void setup() 
{
  ESP.wdtEnable(WDTO_2S);
  Serial.begin(9600);
  readerSerial.begin(9600);  
  delay(10);
  
  pinMode(pinSwitch1, OUTPUT); // prepare GPIOs
  pinMode(pinSwitch2, OUTPUT);
  pinMode(pinSwitch3, OUTPUT);
  pinMode(pinSwitch4, OUTPUT);
  digitalWrite(pinSwitch1, LOW); // output is Low (0V)
  digitalWrite(pinSwitch2, LOW);
  digitalWrite(pinSwitch3, LOW);
  digitalWrite(pinSwitch4, LOW);
  
  WiFi.begin(ssid, password);
  
  while (WiFi.status() != WL_CONNECTED) 
  {
    WiFiStart();  // inital connect
  }
}

void WiFiStart()
{
  WiFi.begin(ssid, password);
  
  while (WiFi.status() != WL_CONNECTED) 
  {
    delay(500);
    Serial.print(".");
  }
  server.begin(); // Start the server  
}

void loop() 
{ 
  if (WiFi.status() != WL_CONNECTED)
  {
    WiFiStart();
  }
  client = server.available(); // Check if a client has connected
  if (!client) 
  {   
      unsigned long currentMillis = millis(); // Get snapshot of time  
      
      while(readerSerial.available() > 0) 
      {
         incomingData = readerSerial.read(); // <------------------------This is the stuff that reads out the RFID reader
         Serial.print("Data received: ");
         Serial.println(incomingData);
         TagData = TagData + String(incomingData);
         Serial.print("TagData received: ");
         Serial.println(TagData);     
      }
      
      if((unsigned long)(currentMillis - startMillis1) >= enableTimeSwitch1 && enableTimeSwitch1 !=0 ) // How much time has passed, accounting for rollover with subtraction!
      {
        digitalWrite(pinSwitch1, LOW); // Switch1 off
        valueSwitch1 = 0;
        enableTimeSwitch1 = 0;
        Serial.println("Switch1 is now Off");
      } 
      if((unsigned long)(currentMillis - startMillis2) >= enableTimeSwitch2 && enableTimeSwitch2 !=0)
      {
        digitalWrite(pinSwitch2, LOW); // Switch2 off
        valueSwitch2 = 0;
        enableTimeSwitch2 = 0;
        Serial.println("Switch2 is now Off");
      }
      if((unsigned long)(currentMillis - startMillis3) >= enableTimeSwitch3 && enableTimeSwitch3 !=0)
      {
        digitalWrite(pinSwitch3, LOW); // Switch3 off
        valueSwitch3 = 0;
        enableTimeSwitch3 = 0;
        Serial.println("Switch3 is now Off");
      }
      if((unsigned long)(currentMillis - startMillis4) >= enableTimeSwitch4 && enableTimeSwitch4 !=0)
      {
        digitalWrite(pinSwitch4, LOW); // Switch4 off
        valueSwitch4 = 0;
        enableTimeSwitch4 = 0;
        Serial.println("Switch4 is now Off");
      }      

      ESP.wdtFeed(); // Reset the WatchDog
      client.stop();
      return;
  }    
  Serial.println("new client"); // Wait until the client sends some data
  while(!client.available())
  { delay(1); }
  
  String req = client.readStringUntil('\r'); // Read the first line of the request
  Serial.println(req);
  client.flush();
  
  // Match the request

  int indexOfTime = req.indexOf("time=");
  unsigned long enableTime = (req.substring(indexOfTime+5)).toInt();
  enableTime = enableTime*1000;

  if (req.indexOf("/Data") != -1)
  { sendRFIDReaderData(); return; } 
  else if (req.indexOf("/GetStatus") != -1)
  { sendResponse(); return; }                     // send actual status of switches On or Off
  else if (req.indexOf("/Reset") != -1)
  { 
    sendResponse(); 
    Serial.println("Restart ESP now"); 
    delay(200); 
    ESP.restart();
    return; 
  }
      
  else if (req.indexOf("/switch1/on") != -1)
  { valueSwitch1 = 1; enableTimeSwitch1 = enableTime; startMillis1 = millis(); }  
  else if (req.indexOf("/switch2/on") != -1)
  { valueSwitch2 = 1; enableTimeSwitch2 = enableTime; startMillis2 = millis(); }
  else if (req.indexOf("/switch3/on") != -1)
  { valueSwitch3 = 1; enableTimeSwitch3 = enableTime; startMillis3 = millis(); }
  else if (req.indexOf("/switch4/on") != -1)
  { valueSwitch4 = 1; enableTimeSwitch4 = enableTime; startMillis4 = millis(); }
  
  else 
  {
    Serial.println("invalid request");
    client.stop();
    return;
  }
  delay(1);
  
    Serial.println("EnableTime: " + enableTime);    
         
    digitalWrite(pinSwitch1, valueSwitch1); // Set Switches according to the request
    digitalWrite(pinSwitch2, valueSwitch2); // "0" = 0V, "1" = 3.3V
    digitalWrite(pinSwitch3, valueSwitch3);
    digitalWrite(pinSwitch4, valueSwitch4);

    sendResponse();
    ESP.wdtFeed();
}

void sendResponse() 
{
  client.flush(); // Discard any bytes that have been written to the client but not yet read
  String s = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n<!DOCTYPE HTML>\r\n<html>\r\n<strong>Switch1:</strong> "; // Prepare the response
  s += (valueSwitch1)?"ON
":"OFF
";
  s += "<strong>Switch2:</strong> ";
  s += (valueSwitch2)?"ON
":"OFF
";
  s += "<strong>Switch3:</strong> ";
  s += (valueSwitch3)?"ON
":"OFF
";
  s += "<strong>Switch4:</strong> ";
  s += (valueSwitch4)?"ON

":"OFF

";
  s += "<a href=\"/Data\">http://server_ip/Data --> Get data from RFID-Reader</a>

";
  s += "<a href=\"/GetStatus\">Refresh Website</a>";
  s += "</html>\n";
  client.print(s);// Send the response to the client
  delay(1);
}

void sendRFIDReaderData()
{
  client.flush(); // Discard any bytes that have been written to the client but not yet read
  String s = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n<!DOCTYPE HTML>\r\n<html>\r\n<strong>RFID-TAG Data:</strong> "; // Prepare the response
  s += TagData + "

"; // This is TagData "6316623023020350204463838412142420"
  s += "<a href=\"/GetStatus\">Back to Homepage</a>";
  s += "</html>\n";
  client.print(s); // Send the response to the client

  delay(1);
  Serial.println("Client disonnected"); // The client will actually be disconnected. When the function returns and 'client' object is detroyed
  
  if (client.connect(http_site, http_port)) 
  {
    Serial.println("Connected to URL");
    Serial.print("TagData: "); Serial.println(TagData);
    // Make a HTTP request:
    String s = "GET /ESP.php?TagID="; // Prepare the response
    s += TagData;
    s += "&switch1=";
    s += valueSwitch1;
    s += "&switch2=";
    s += valueSwitch2;
    s += "&switch3=";
    s += valueSwitch3;
    s += "&switch4=";
    s += valueSwitch4;
    s += " HTTP/1.1";
    client.println(s);
    
    client.print("Host: ");
    client.println(http_site);
    client.println("Connection: close");
    client.println();      
  }
  else 
  {
    Serial.println("Connection failed"); // kf you didn't get a connection to the server:
  }  
  TagData = "";
}

The interesting thing for reading out the Reader is in the main loop.
In the attachment you can find the Serial output of:

while(readerSerial.available() > 0) 
      {
         incomingData = readerSerial.read(); // <------------------------This is the stuff that reads out the RFID reader
         Serial.print("Data received: ");
         Serial.println(incomingData);
         TagData = TagData + String(incomingData);
         Serial.print("TagData received: ");
         Serial.println(TagData);     
      }

I´m in the RS232 Mode of the reader because the Tibbo Serial-Wifi outputs the correct format.

int incomingData;

So, finally, we know the type.

         incomingData = readerSerial.read(); // <------------------------This is the stuff that reads out the RFID reader
         Serial.print("Data received: ");
         Serial.println(incomingData);

Please do not post pictures of text.

Since you know that there is data to read, the data CAN be stored in a char or byte type variable, instead of an int. Doing so might just make handling the data more intuitive/obvious.

The data coming in is not in the ASCII character range, so trying to make a String of it does not make sense. You will never make the String match anything on the card/chip.

On the other hand, why do you need to? You scan a card. You get an array of bytes. That either matches a known array, or it doesn't.

dawinci:
When i swipe a RFID Tag over the reader i get "010D68F03C" back from the Tibbo COM-port.

So the reader is working and outputting an ASCII coded string.

Looking at the other strings i see no evidence of that card being present.

I suspect the problem lies with your tibo system.

The quoted format from the reader is 14 bytes.

You have 34 bytes or blocks being read.

Have you updated the firmware of your ESP8266 to operate as a data bridge ?

Just poking serial into its inputs is unlikely to work.

Back to basics.

Post a block diagram of your (working ?) setup using tibo.

Post a diagram of the non working diagram using ESP8266.

Draw the arduino(s), reader , tibo , esp8266, and server/website as boxes and show how they are interconnected.

In addition get another card.

Simple test.

Read that and compare with the output , it should be different.