Hi,
I have an RFID reader and NodeMCU mounted in the same box. Seems when my reader reads the card, wifi doesn't seem to connect. I think it may be interference. I read that I could possibly separate my code so that after the RFID reads, it stops that portion allowing the Wifi to connect. Not sure if that makes sense. Below is my code, any thoughts to fix this. thanks
/*
Many thanks to nikxha from the ESP8266 forum
*/
#include <ESP8266WiFi.h>
#include <WiFiClientSecure.h>
#include <SPI.h>
//#include "MFRC522.h"
#include <PubSubClient.h>
#include <MFRC522.h>
#include "CTBot.h"
CTBot myBot;
/* wiring the MFRC522 to ESP8266 (ESP-12)
RST = GPIO5
SDA(SS) = GPIO4
MOSI = GPIO13
MISO = GPIO12
SCK = GPIO14
GND = GND
3.3V = 3.3V
*/
#define RST_PIN 5 // RST-PIN für RC522 - RFID - SPI - Modul GPIO5
#define SS_PIN 4 // SDA-PIN für RC522 - RFID - SPI - Modul GPIO4
#define LED D0 // Led in NodeMCU at pin GPIO5 (D4).
String ssid = "xx"; // REPLACE mySSID WITH YOUR WIFI SSID
String pass = "xxxx"; // REPLACE myPassword YOUR WIFI PASSWORD, IF ANY
const char* mqtt_server = "192.168.0.xxx";
WiFiClient espClient;
PubSubClient client(espClient);
long lastMsg = 0;
char msg[50];
int value = 0;
char message_buff[200];
String token = "xxxx"; // your Bot Token (Get from Botfather)
#define CHAT_ID "xxxx" // Chat ID of where you want the message to go (You can use MyIdBot to get the chat ID)
MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance.
void setup()
{
Serial.begin(115200); // Initialize serial communications
delay(250);
Serial.println(F("Booting...."));
client.setServer(mqtt_server, 1883);
SPI.begin(); // Initiate SPI bus
Serial.println("Starting TelegramBot...");
// connect the ESP8266 to the desired access point
mfrc522.PCD_Init(); // Initiate MFRC522
WiFi.begin(ssid, pass);
// set the telegram bot token
myBot.setTelegramToken(token);
int retries = 0;
while ((WiFi.status() != WL_CONNECTED) && (retries < 10)) {
retries++;
delay(500);
Serial.print(".");
}
if (WiFi.status() == WL_CONNECTED) {
Serial.println(F("WiFi connected"));
Serial.println("Present Your Card...");
Serial.println();
}
pinMode(LED, OUTPUT); // set the digital pin as output.
// digitalWrite(LED, HIGH);//turn LED on
// delay(5);
}
void loop()
{
// 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.print("UID tag is:");
String content= "";
byte letter;
for (byte i = 0; i < mfrc522.uid.size; i++)
{
Serial.print(mfrc522.uid.uidByte < 0x10 ? " 0" : " ");
_ Serial.print(mfrc522.uid.uidByte*, HEX);_
_ content.concat(String(mfrc522.uid.uidByte < 0x10 ? " 0" : " "));
content.concat(String(mfrc522.uid.uidByte, HEX));
}
Serial.println();
//Serial.println("Card UID is:");
//content.toUpperCase();
// Serial.println(content.substring(1));
Serial.print("Message : ");
content.toUpperCase();
if (content.substring(1) == "04 7E 73 C2 A8 64 99") //change here the UID of the card/cards that you want to give access*
* {
Serial.println("Authorized access");
Serial.println();
delay(3000);
}*_
else {
* client.loop();*
* //Serial.println(" Access denied");*
digitalWrite(LED, HIGH); // turn the LED on
delay(1000); // wait for a second
digitalWrite(LED, LOW); // turn the LED off
delay(1000); // wait for a second
* Serial.print("Attempting MQTT connection...");*
* if (client.connect("arduinoClient", "xxx", "xxx"))*
content.substring(1).toCharArray(message_buff, 20);
* client.publish("RFID/FrontDoor/", message_buff);
_ myBot.sendMessage(xxx, "RFID Front Door Scanned:");_
myBot.sendMessage(xxx, message_buff);
_ delay(2000);
}
}*_