Bonjour à tous ! J'essai de d'envoyer l'UID (numéro d'identification d'un TAG) en utilisant le module RFID RC522 et un Nodemcu ESP8266 vers une page HTML.
En ce moment mon code permet de capter l'UID et l'affiché sur le Serial Monitor, j'ai réussi à recevoir simple un message Hello world sur une page HTML, mais je bloque lorsqu'il s'agit d'envoyer l'UID sur la page HTML...
Merci d'avance !
Voici mon 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);
}
}