Hi folks ! I'm trying to send the UID from a RC522 RFID TAG to an HTML page.
In that moment with my code I can only show the UID on the serial monitor and write a send a text to an HTML page... Moreover I heard about socket (a command to send datas to a server, I don't know what it is it...)
This is my code :
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <MFRC522.h>
#define RST_PIN 0 // RST-PIN for RC522 - RFID - SPI - Modul GPIO5
#define SS_PIN 2 // SDA-PIN for RC522 - RFID - SPI - Modul GPIO4
MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance
//SSID and Password to your ESP Access Point
const char* ssid = "MySSID_ESP8266";
const char* password = "123456789";
ESP8266WebServer server(80); //Server on port 80
//==============================================================
// This rutine is exicuted when you open its IP in browser
//==============================================================
void handleRoot()
{
server.send(200, "text/plain", "dump_byte_array");
}
//=============================================
void setup(void) // SETUP
//=============================================
{
//===============================================================
// SETUP ACCES POINT
//===============================================================
Serial.begin(115200); // Initialize serial communications (Serial.begin(9600));
Serial.println("");
WiFi.mode(WIFI_AP); //Only Access point
WiFi.softAP(ssid, password); //Start HOTspot removing password will disable security
IPAddress myIP = WiFi.softAPIP(); //Get IP address
Serial.print("HotSpt IP:");
Serial.println(myIP);
server.on("/", handleRoot); //Which routine to handle at root location
server.begin(); //Start server
Serial.println("HTTP server started");
//===============================================================
// SETUP MFRC522
//===============================================================
//Serial.begin(115200);
SPI.begin(); // Init SPI bus
mfrc522.PCD_Init(); // Init MFRC522
}
//===============================================
void loop(void) // LOOP
//===============================================
{
//===============================================================
// LOOP ACCES POINT
//===============================================================
server.handleClient();//Handle client requests
//==============================================================
// LOOP MFRC522
//==============================================================
// 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);
Serial.println();
}
// Helper routine to dump a byte array as hex values to Serial
void dump_byte_array(byte *buffer, byte bufferSize)
{
for (byte i = 0; i < bufferSize; i++)
{
Serial.print(buffer[i] < 0x10 ? " 0" : " ");
Serial.print(buffer[i], HEX);
}
}