BLYNK
HOME       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

NodeMCU and reporting virtual pin value

#1

I have a NodeMCU connected to a RFID-RC522 with a local Blynk server on a Raspberry Pi.

When a tag is scanned a red or green led is lit depending on the tag. and the tag and result sent to the Blynk app on my tablet via a virtual pin

This is working just fine.

What I am trying to do is use the reporting module to export a history of tags, result and date/time, but when I run the report on the virtual pin there is no data to export.

Code below.

//RFID Declarations
#include <RFID.h>
#include <SPI.h>

#define SS_PIN D4
#define RST_PIN D3

RFID rfid(SS_PIN, RST_PIN);
bool access = false;
String cardno = "";
int numRows = 0;
//Maximum of 15 records.
String rfids[][3]
{
  {"7076987", "Purple Dragon", "no"},
  {"24186131", "Mad Gunslinger", "yes"},
  {"1364139128", "Elsa", "no"},
  {"1364236158", "Darth Maul", "no"},
  {"19415315163", "Copper Dragon", "no"},
  {"166124109203", "Tree Monster", "yes"},
  {"136436117", "Leia", "no"},
  {"13644475", "Luke", "yes"},
};

#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>

// Your WiFi credentials.
const char* ssid = "SSID";
const char* password = "password";
ESP8266WebServer server(80);
String page = "";

#define BLYNK_PRINT Serial
#include <BlynkSimpleEsp8266.h>

//LED Declarations
int RedLED = D2;
int GrnLED = D1;
//End LED

//Blynk
char auth[] = "AuthToken";
BlynkTimer timer;

String token;
String msg;

void setup()
{
  Serial.begin(9600);
  //RFIDSetup
  Serial.println("SPI Start");
  SPI.begin();
  Serial.println("Init RFID");
  rfid.init();
  numRows = sizeof(rfids) / sizeof(rfids[0]);
  Serial.print("Number of rows = ");
  Serial.println(numRows);
  Serial.print("Connecting to ");
  Serial.println(ssid);
 
  WiFi.begin(ssid, password);

  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.println("WiFi connected");

  // Start the server
  server.begin();
  Serial.println("Server started");
 
  // Print the IP address
  Serial.print("Use this URL to connect: ");
  Serial.print("http://");
  Serial.print(WiFi.localIP()); //Gets the WiFi shield's IP address and Print the IP address of serial monitor
  Serial.println("/");
  
  //LED Setup
  pinMode(RedLED, OUTPUT);
  pinMode(GrnLED, OUTPUT);

  Blynk.begin(auth, ssid, password, IPAddress(10,10,0,117), 8080);
  msg = "Server started";

}

void loop()
{
  // put your main code here, to run repeatedly:
  Blynk.run();
  cardRead();
  server.handleClient();
}

void cardRead()
{
  token="";
  if(rfid.isCard())
  {
    if(rfid.readCardSerial())
    {
      int IDlen = 4;
      cardno = "";
      for(int i = 0; i < IDlen; i++)
      {
        cardno += rfid.serNum[i];
      }
      Serial.print("Card - ");
      Serial.println(cardno);
      for(int x = 0; x < numRows; x++)
      {
        access = false;
        if(cardno != rfids[x][0])
        {
          access = false;
        }
        else
        {
          if (rfids[x][2] == "yes")
          {
            access = true;
            token = rfids[x][1];
            break;
          }
          else
          {
            access = false;
            token = rfids[x][1];
          }
          break;
        }
      }
      accessAction();
    }
  }
}

void accessAction(){
  //CheckAccess
  if(access)
  {
    msg = token + " - allow";
    Blynk.virtualWrite(V5, msg);
    Blynk.syncAll();
    digitalWrite(GrnLED, HIGH);
    Serial.println(msg);
    delay(2000);
    digitalWrite(GrnLED, LOW);
  }
  else
  {
    msg = token + " - deny";
    //Flash Red LED
    Serial.println(msg);
    Blynk.virtualWrite(V5, msg);
    Blynk.syncAll();
    for (int i = 0; i <= 5; i++){
      digitalWrite(RedLED, HIGH);
      delay(100);
      digitalWrite(RedLED, LOW);
      delay(100);
    }
    delay(1000);
  }
  server.on("/", [](){
    page = "<h1>Sensor to Node MCU Web Server</h1><h3>Data:</h3> <h4>"+String(msg)+"</h4>";
    server.send(200, "text/html", page);
  });
}




0 Likes

#2

I think that the virtual pins have to be used in a SuperChart to enable them to be used in the reporting widget.
However, this might not work exactly the way that you wnat it to, because of the way that values are averaged. See the ‘granularity section of the SuperChart documentation:
https://docs.blynk.cc/#widgets-displays-superchart

Pete.

0 Likes

#3

Thanks for that, looks like I’m going to have to go back to basics and parse the raw log file myself.

Do you know where the detail log is written,assuming the data is even logged.

0 Likes

#4

Back to basics, I’m reporting to FireBase and going to extract from there.

0 Likes