Hello to everyone , i use this code :
#include <Wire.h>
#include <RTClib.h>
#include <Arduino.h>
#include <MFRC522.h>
#include <WiFiS3.h>
#include <Firebase_ESP_Client.h>
// Provide the token generation process info.
#include "addons/TokenHelper.h"
// Provide the RTDB payload printing info and other helper functions.
#include "addons/RTDBHelper.h"
#define SS_PIN 10
#define RST_PIN 9
// Replace these with your actual WiFi credentials
#define WIFI_SSID "ORIGINAL21" // Your WiFi SSID
#define WIFI_PASSWORD "..." // Your WiFi Password
#define DATABASE_URL "..."
#define API_KEY "...."
MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance
FirebaseData fbdo;
FirebaseAuth auth;
FirebaseConfig config;
RTC_DS3231 rtc;
void setup() {
Serial.begin(115200); // Ensure this matches the Serial Monitor baud rate
// Initialize WiFi
Serial.println("Connecting to WiFi...");
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
while (WiFi.status() != WL_CONNECTED) {
Serial.print(".");
delay(1000);
}
Serial.println("\nWiFi connected");
Serial.print("Connected with IP: ");
Serial.println(WiFi.localIP());
// Firebase configuration
Serial.println("Configuring Firebase...");
config.api_key = API_KEY;
config.database_url = DATABASE_URL;
auth.user.email = "....";
auth.user.password = "....";
Firebase.begin(&config, &auth);
Firebase.reconnectWiFi(true);
Serial.println("Firebase initialized");
// Initialize RTC
Serial.println("Initializing RTC...");
if (!rtc.begin()) {
Serial.println("Couldn't find RTC");
while (1);
}
if (rtc.lostPower()) {
Serial.println("RTC lost power, let's set the time!");
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
}
// Initialize SPI and MFRC522
Serial.println("Initializing SPI and MFRC522...");
SPI.begin();
mfrc522.PCD_Init();
Serial.println("Approximating your card to the reader...");
}
void loop() {
if (!Firebase.ready()) {
Serial.println("Firebase not ready, reconnecting...");
Firebase.begin(&config, &auth); // Reinitialize Firebase
return;
}
// Check for RFID tag
if (!mfrc522.PICC_IsNewCardPresent()) {
return;
}
if (!mfrc522.PICC_ReadCardSerial()) {
return;
}
Serial.println("RFID Tag detected!");
// Show UID on serial monitor
Serial.print("UID tag: ");
char content[32] = {0};
for (byte i = 0; i < mfrc522.uid.size; i++) {
char hexDigit[3];
sprintf(hexDigit, "%02X", mfrc522.uid.uidByte[i]);
strcat(content, hexDigit);
}
Serial.println(content);
// Get current time from RTC
DateTime now = rtc.now();
char currentTime[20];
sprintf(currentTime, "%04d-%02d-%02d %02d:%02d:%02d", now.year(), now.month(), now.day(), now.hour(), now.minute(), now.second());
Serial.println("Current Time: " + String(currentTime));
// Prepare the path and the value to set in the database
char path[64];
char tagValue[128];
sprintf(path, "/rfid_tags/%s", content); // Path in Firebase where the data will be stored
sprintf(tagValue, "Tag read at: %s", currentTime);
// Debug print to check if path and tagValue are correct
Serial.println("Path: " + String(path));
Serial.println("Tag Value: " + String(tagValue));
// Send UID and a timestamp to Firebase Database
Serial.println("Sending data to Firebase...");
if (Firebase.RTDB.setString(&fbdo, path, tagValue)) {
Serial.println("Stored RFID tag to Firebase successfully!");
} else {
Serial.println("Failed to store data in Firebase!");
Serial.println("Reason: " + fbdo.errorReason());
}
// Halt PICC
mfrc522.PICC_HaltA();
delay(1000); // Add a delay to avoid flooding the serial output
}
and i have this error:Fault on interrupt or bare metal(no OS) environment
Error: Main stack(200075d0) was overflow
i use arduino uno R4 wifi board.It has esp32-S3 .