RFID unable to send data to Blynk

Hi everyone. I’m working with an ESP32 and a mfrc522 RFID module. In this example, I’m just trying to send to blynk that the card was read successfully, but it doesn’t seem to work.
Just does nothing.
Do you have any idea where can I be mistaken?
Thnaks in advance

#define BLYNK_TEMPLATE_ID "TMPLXKDu5xz2"
#define BLYNK_DEVICE_NAME "pControlAcceso"

#define BLYNK_FIRMWARE_VERSION        "0.1.0"

#define BLYNK_PRINT Serial
//#define BLYNK_DEBUG

#define APP_DEBUG

#define USE_ESP32S2_DEV_KIT

#include "BlynkEdgent.h"

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

#define SS_PIN 21
#define RST_PIN 22

MFRC522 mfrc522(SS_PIN, RST_PIN); 

byte tarjetaLeida[4];
void setup()
{
 Serial.begin(115200);
 SPI.begin();
 mfrc522.PCD_Init();
 delay(100);

 BlynkEdgent.begin();
}

void loop()
{
 BlynkEdgent.run();
  if ( ! mfrc522.PICC_IsNewCardPresent())
   return;

 if ( ! mfrc522.PICC_ReadCardSerial())
   return;

 Serial.print("UID: ");
 for (byte i = 0; i < mfrc522.uid.size; i++)
 {
   if (mfrc522.uid.uidByte[i] < 0x10)
   {
     Serial.print(" 0");
   }
   else
   {
     Serial.print(" ");
   }
   tarjetaLeida[i] = mfrc522.uid.uidByte[i] , HEX;
   Serial.print(mfrc522.uid.uidByte[i], HEX);
   
   Serial.println();
 }
 Blynk.virtualWrite(V1,"Tarjeta Leida");
 Serial.println();
 mfrc522.PICC_HaltA();
}



These three lines of code are outside of any if statement, so are executed every single time the void loop executes.
This could be hundreds of times per second, so you are flooding the Blynk server with virtualWrites.

Pete.

1 Like

Excuse me Pete
When I run this code without Blynk, it works perfectly
But when I migrate it to Blynk, it stops working
Just asking it to send a message to Blynk, and it doesn’t do anything
I’m wondering if there’s a kind of blocking while using the module RFID MC522 on ESP32 and blynk
I’ve seen some other projects here in the community but with ESP8266 and the previous Blynk version

Have you tried using a timer to execute your code rather than putting it inside the void loop ?

https://docs.blynk.io/en/legacy-platform/legacy-articles/keep-your-void-loop-clean?q=Loop

When you run it without Blynk you don’t have this line of code in your void loop…

With that line in there, and not inside any if statement you are flooding the Blynk server.

Pete.