# RFID is not detected in Node Red

**URL:** https://discourse.nodered.org/t/rfid-is-not-detected-in-node-red/47685
**Category:** General
**Created:** [25 June 2021 21:55 UTC](https://discourse.nodered.org/t/rfid-is-not-detected-in-node-red/47685 "2021-06-25T21:55:41Z")
**Posts on this page:** 14
**Page:** 1

<div class="post-metadata">

### Author: ![nurulh1909](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/nurulh1909/32/39779_2.png) [@nurulh1909](https://discourse.nodered.org/u/nurulh1909)
#### Post date: [25 June 2021 21:55 UTC](https://discourse.nodered.org/t/rfid-is-not-detected-in-node-red/47685/1 "2021-06-25T21:55:42Z")

</div>

Hi, my project is about the RFID it will detected by the MQTT node named RFID Collection. But My RFID is run with NodeMCU and has been coded as below using Arduino and it works well as displayed in the COM Serial, the RFID is detected but not in the Node Red. I want the RFID to be detected and change the switch shown in the dashboard .

```auto
#include <ESP8266WiFi.h>
#include <PubSubClient.h>
#include <MFRC522.h>
#include <SPI.h>
#include "NewPing.h" // include NewPing library

#define SS_PIN 4 //D2
#define RST_PIN 5 //D1

// Lamp - LED - GPIO 0 = D4 on ESP-12E NodeMCU board
const int ledPin = 0;

const char* ssid = "AndroidAP";
const char* password = "lalalo1234";
const char* mqtt_server = "192.168.43.114";// Change the variable to your Raspberry Pi IP address, so it connects to your MQTT broker

// Create MFRC522 instance.
MFRC522 mfrc522(SS_PIN, RST_PIN);   
int statuss = 0;
int out = 0;

// setup mqtt client
WiFiClient espClient;
PubSubClient client(espClient);

void setup_wifi() {

  delay(10);
  // We start by connecting to a WiFi network
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);

  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, password);

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

  Serial.println("");
  Serial.print("WiFi connected - ESP IP address: ");
  Serial.println(WiFi.localIP());
}

void callback(String topic, byte* message, unsigned int length) {
  Serial.print("Message arrived on topic: ");
  Serial.print(topic);
  Serial.print(". Message: ");
  String messageTemp;

  for (int i = 0; i < length; i++) {
    Serial.print((char)message[i]);
    messageTemp += (char)message[i];
  }
  Serial.println();

  // If a message is received on the topic room/lamp, you check if the message is either on or off. Turns the lamp GPIO according to the message
  if(topic=="home/levelsensor"){
      Serial.print("Measuring level ");
      if (messageTemp == "on"){
        digitalWrite(ledPin, HIGH);
        Serial.print("On");
      }
      else if(messageTemp == "off"){
        digitalWrite(ledPin, LOW);
        Serial.print("Off");
      }
  }
  Serial.println();
}

void reconnect() {
  // Loop until we're reconnected
  while (!client.connected()) {
    Serial.print("Attempting MQTT connection...");
    // Attempt to connect

  if (client.connect("ESP8266Client")) {
      Serial.println("connected");  
      // Subscribe or resubscribe to a topic
      // You can subscribe to more topics (to control more LEDs in this example)
      client.subscribe("room/lamp");
    } else {
      Serial.print("failed, rc=");
      Serial.print(client.state());
      Serial.println(" try again in 5 seconds");
      // Wait 5 seconds before retrying
      delay(5000);
    }
  }
}

// The setup function sets your ESP GPIOs to Outputs, starts the serial communication at a baud rate of 115200
// Sets your mqtt broker and sets the callback function
// The callback function is what receives messages and actually controls the LEDs
void setup() {
// pinMode(ledPin, OUTPUT);
  SPI.begin(); // Initiate SPI bus
  mfrc522.PCD_Init(); // Initiate MFRC522

 // dht.begin();
  
  Serial.begin(115200);
  setup_wifi();
  client.setServer(mqtt_server, 1883);
  client.setCallback(callback);
}
void loop() {
   if (!client.connected()) {
    reconnect();
  }
  if(!client.loop())
    client.connect("ESP8266Client");

  // Look for new cards
  if ( ! mfrc522.PICC_IsNewCardPresent()) 
  {
    return;
  }
  // Select one of the cards
  if ( ! mfrc522.PICC_ReadCardSerial()) 
  {
    return;
  }
  //Show UID on serial monitor
  Serial.println();
  Serial.print(" UID tag :");
  String content= "";
  byte letter;
  for (byte i = 0; i < mfrc522.uid.size; i++) 
  {
     Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
     Serial.print(mfrc522.uid.uidByte[i], HEX);
     content.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));
     content.concat(String(mfrc522.uid.uidByte[i], HEX));
  }
  content.toUpperCase();
  Serial.println();
  if (content.substring(1) == "2A 44 4F B3") //change UID of the card that you want to give access
  {
    client.publish("rfid/collection","true");
    Serial.println(" Access Granted ");
    Serial.println(" Welcome Mr.Circuit ");
    delay(1000);
    Serial.println(" Have FUN ");
    Serial.println();
    statuss = 1;
  }
  
  else {
    Serial.println(" Access Denied ");
    delay(3000);
  }
    }   
    

```

Maybe something is wrong with the my Client Publish . Any suggestion?

Below is my node red code :

[{"id":"86cdf9d1.c16778","type":"mqtt in","z":"71d2c1a.f8a4f4","name":"RFID Collection","topic":"rfid/collection","qos":"0","datatype":"auto","broker":"4c17587e.e718a8","nl":false,"rap":true,"rh":0,"x":240,"y":180,"wires":[["3cfc3d34.110cc2"]]},{"id":"4c17587e.e718a8","type":"mqtt-broker","name":"MQTT Connected","broker":"localhost","port":"1883","clientid":"","usetls":false,"protocolVersion":"4","keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","birthMsg":{},"closeTopic":"","closeQos":"0","closePayload":"","closeMsg":{},"willTopic":"","willQos":"0","willPayload":"","willMsg":{},"sessionExpiry":""}]

---

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [25 June 2021 22:02 UTC](https://discourse.nodered.org/t/rfid-is-not-detected-in-node-red/47685/2 "2021-06-25T22:02:20Z")

</div>

Have you tested the broker on your raspberry pi can be connected to from a networked computer?

What type and version broker are you running on the raspberry?

---

<div class="post-metadata">

### Author: ![nurulh1909](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/nurulh1909/32/39779_2.png) [@nurulh1909](https://discourse.nodered.org/u/nurulh1909)
#### Post date: [25 June 2021 22:11 UTC](https://discourse.nodered.org/t/rfid-is-not-detected-in-node-red/47685/3 "2021-06-25T22:11:58Z")

</div>

its mosquitto version 1.5.7

1624659078: mosquitto version 1.5.7 starting  
1624659078: Using default config.  
1624659078: Opening ipv4 listen socket on port 1883.  
1624659078: Error: Address already in use

---

<div class="post-metadata">

### Author: ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)
#### Post date: [25 June 2021 22:58 UTC](https://discourse.nodered.org/t/rfid-is-not-detected-in-node-red/47685/4 "2021-06-25T22:58:43Z")

</div>

> [@nurulh1909](#):
>
> 1624659078: Error: Address already in use

This could be problematic.

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [26 June 2021 07:51 UTC](https://discourse.nodered.org/t/rfid-is-not-detected-in-node-red/47685/5 "2021-06-26T07:51:07Z")

</div>

The port is already in use. Do you have another broker running already?  
What does the command  
`sudo netstat -ltnp | grep -w ':1883'`  
show? If it says the command is not found then run  
`sudo apt install net-tools`  
to install it.

---

<div class="post-metadata">

### Author: ![nurulh1909](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/nurulh1909/32/39779_2.png) [@nurulh1909](https://discourse.nodered.org/u/nurulh1909)
#### Post date: [26 June 2021 10:22 UTC](https://discourse.nodered.org/t/rfid-is-not-detected-in-node-red/47685/6 "2021-06-26T10:22:58Z")

</div>

> [@Colin](#):
>
> sudo netstat -ltnp | grep -w ':1883'

tcp6 0 0 :::1883 :::\* LISTEN 502/mosquitto

---

<div class="post-metadata">

### Author: ![nurulh1909](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/nurulh1909/32/39779_2.png) [@nurulh1909](https://discourse.nodered.org/u/nurulh1909)
#### Post date: [26 June 2021 10:23 UTC](https://discourse.nodered.org/t/rfid-is-not-detected-in-node-red/47685/7 "2021-06-26T10:23:27Z")

</div>

$ sudo apt install net-tools  
E: dpkg was interrupted, you must manually run 'sudo dpkg --configure -a' to correct the problem.

---

<div class="post-metadata">

### Author: ![nurulh1909](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/nurulh1909/32/39779_2.png) [@nurulh1909](https://discourse.nodered.org/u/nurulh1909)
#### Post date: [26 June 2021 10:24 UTC](https://discourse.nodered.org/t/rfid-is-not-detected-in-node-red/47685/8 "2021-06-26T10:24:29Z")

</div>

sudo dpkg --configure -a  
Setting up apache2 (2.4.38-3+deb10u4) ...

Configuration file '/etc/apache2/apache2.conf'  
==\> File on system created by you or by a script.  
==\> File also in package provided by package maintainer.  
What would you like to do about it ? Your options are:  
Y or I : install the package maintainer's version  
N or O : keep your currently-installed version  
D : show the differences between the versions  
Z : start a shell to examine the situation  
The default action is to keep your current version.  
\*\*\* apache2.conf (Y/I/N/O/D/Z) [default=N] ?

what should I proceed ?

---

<div class="post-metadata">

### Author: ![nurulh1909](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/nurulh1909/32/39779_2.png) [@nurulh1909](https://discourse.nodered.org/u/nurulh1909)
#### Post date: [26 June 2021 10:25 UTC](https://discourse.nodered.org/t/rfid-is-not-detected-in-node-red/47685/9 "2021-06-26T10:25:11Z")

</div>

> [@nurulh1909](#):
>
> its mosquitto version 1.5.7

its mosquitto version 1.5.7

---

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [26 June 2021 10:31 UTC](https://discourse.nodered.org/t/rfid-is-not-detected-in-node-red/47685/10 "2021-06-26T10:31:12Z")

</div>

ok, so can you access the mosquito broker from an external computer using an MQTT client (e.g. MQTT Explorer). Do you see a topic `home/levelsensor` ?

Are you publishing a value to `home/levelsensor`? from somewhere?

* * *

Is the IP/username/password set correctly in your `c` code?

```auto
const char* ssid = "AndroidAP";
const char* password = "lalalo1234";
const char* mqtt_server = "192.168.43.114"

```

Can you look at your DHCP server / router to see if the ESP is connecting to the network?

Do you see "WiFi connected - ESP IP address: xxxxxxxxxx" in the serial console?

Can you ping that IP address?

---

<div class="post-metadata">

### Author: ![nurulh1909](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/nurulh1909/32/39779_2.png) [@nurulh1909](https://discourse.nodered.org/u/nurulh1909)
#### Post date: [26 June 2021 10:42 UTC](https://discourse.nodered.org/t/rfid-is-not-detected-in-node-red/47685/11 "2021-06-26T10:42:02Z")

</div>

yes , there is home/levelsensor somewhere else in another node red flow.

---

<div class="post-metadata">

### Author: ![nurulh1909](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/nurulh1909/32/39779_2.png) [@nurulh1909](https://discourse.nodered.org/u/nurulh1909)
#### Post date: [26 June 2021 10:43 UTC](https://discourse.nodered.org/t/rfid-is-not-detected-in-node-red/47685/12 "2021-06-26T10:43:49Z")

</div>

All is correct, my serial shows that it connected and my MQTT in node red shows green light to say it is connected. My circuit is functioning but seems not reaching my node-red.

---

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [26 June 2021 10:54 UTC](https://discourse.nodered.org/t/rfid-is-not-detected-in-node-red/47685/13 "2021-06-26T10:54:22Z")

</div>

> [@nurulh1909](#):
>
> ```auto
> if (content.substring(1) == "2A 44 4F B3") //change UID of the card that you want to give access
> {
> client.publish("rfid/collection","true");
> Serial.println(" Access Granted ");
> Serial.println(" Welcome Mr.Circuit ");
> delay(1000);
> Serial.println(" Have FUN ");
> Serial.println();
> statuss = 1;
> } else {
> Serial.println(" Access Denied ");
> delay(3000);
> }
> 
> ```

Q1: When you present an RFID card do you see "Access Granted" or "Access Denied" in the serial console?

Q2: Can you see (using something like MQTT explorer) values in the broker for topics...

- `rfid/collection` ?
- `home/levelsensor` ?

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)
#### Post date: [25 August 2021 10:54 UTC](https://discourse.nodered.org/t/rfid-is-not-detected-in-node-red/47685/14 "2021-08-25T10:54:53Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
