1

I want to make RFID Tag as a variable, and push it to the web server. But I struggle to do the Serial.read function.

Any solutions?

Here is my code

#include <ESP8266WiFi.h> 
#include <SPI.h> 
#include <MFRC522.h> 

/* wiring the MFRC522 to ESP8266 (ESP-12) 
SDA(SS) - D4 (GPIO2) 
SCK - D5 (GPIO14) (hw spi) 
MOSI - D7 (GPIO13) (hw spi) 
MISO - D6 (GPIO12) (hw spi)  
IRQ - 
GND - G 
RST - D3 (GPIO0) (FLASH) 
3.3V - 3V 
*/ 

#define RST_PIN D3 // RST-PIN für RC522 - RFID - SPI - Modul GPIO5 
#define SS_PIN D4 // SDA-PIN für RC522 - RFID - SPI - Modul GPIO4 

const char *ssid = "Keluarga"; // change according to your Network - 
cannot be longer than 32 characters! 
const char *pass = "batikpekalongan11"; // change according to your 
Network 

String a;

MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance 
WiFiServer server(80); 

void setup() { 
Serial.begin(115200); // Initialize serial communications 
delay(10); 
Serial.print(F("Booting....")); 

SPI.begin(); // Init SPI bus 
mfrc522.PCD_Init(); // Init MFRC522 

WiFi.begin(ssid, pass); 

int retries = 0; 
while ((WiFi.status() != WL_CONNECTED) && (retries < 10)) { 
retries++; 
delay(500); 
Serial.print("."); 
 } 
if (WiFi.status() == WL_CONNECTED) { 
Serial.println(F("WiFi connected")); 
} 

Serial.println(F("Ready!")); 
Serial.println(F("Scan for Card and print UID:")); 
Serial.print("IP address: "); 
Serial.println(WiFi.localIP()); 

// Start the server
server.begin();
Serial.println("Server started");
  } 

void loop() { 
 // Check if a client has connected
 WiFiClient client = server.available();
 if (!client) {
 return;
 }

 // Look for new cards 
   if ( ! mfrc522.PICC_IsNewCardPresent()) { 
delay(50); 
return; 
} 
// Select one of the cards 
if ( ! mfrc522.PICC_ReadCardSerial()) { 
delay(50); 
return; 
} 
// Show some details of the PICC (that is: the tag/card) 
  Serial.print(F("Card UID:")); 
  dump_byte_array(mfrc522.uid.uidByte, mfrc522.uid.size); 
  a = Serial.readString();
  Serial.println("kakak");
  Serial.println(a); 

// Wait until the client sends some data
Serial.println("new client");
 while(!client.available()){
 delay(1);
 }

// Read the first line of the request
String request = client.readStringUntil('\r');
Serial.println(request);
client.flush();

// Return the response
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println(""); //  do not forget this one
client.println("<!DOCTYPE HTML>");
client.println("<html>");

client.print("Card UID:");
client.print(a);
client.println("</html>");
//delay(1);
//Serial.println("Client disonnected");
//Serial.println("");
} 
  • I've add my code to the the questions. Thank you~ – Qonita Salimah May 6 '17 at 12:37
  • What you already have on the Serial.read ? I cannot see a line. And what you try to read? – mico May 6 '17 at 13:18
  • What makes you think Serial.read() has anything at all to do with the card data? – Majenko May 6 '17 at 14:05
  • I'm sorry if my code didn't look so good. I'm still a beginner in this. I'm trying to read the RFID tag. I thought with Serial.read(), I could read the serial data on serial monitor, from the tagged RFID Card and transform it into a variable. My purpose is to send the RFID tag data to the web server. ~Thankyou (sorry for my bad english) – Qonita Salimah May 6 '17 at 17:29
  • Reading from the serial port does not read back what you wrote to it. It looks like the data you want is in mfrc522.uid.uidByte, so try to get that into a. You'll need to format it - you might find clues in your dump_byte_array function. – Mark Smith May 6 '17 at 21:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.