This project is in active development. Feedback, ideas, suggestions, and PRs welcome.
This RFID Logger project uses the ThingPulse board specifically because of the low-power feature. (likely adaptable to other ESP32 boards, as well) along with an RFID reader such as this Mifare RC522 RFID Reader on Amazon. The intention of this project is to keep track of staff movements similar to an IN/OUT attendance board. Clearly much of the reliability and accuracy is based on the honor system to ensure cards are consistently used.
The Arduino MKRWi-Fi 1010, as well as the NodeMCU ESP8266 can also be used by uncommenting the settings in the GlobalDefine.h file.
See Project Emclosure Assembly Information.
The microcontroller waits for a card to be detected. Once a card is present, the UID is read and sent to a web server over HTTPS which saves the information in a SQL table.
In concept, this project could be used to control pretty much anything with the swipe of an RFID card. The receiving code could also be readily modified to save data to other databases, or even a text file.
Although this project focuses on the ESP32, the ESP8266 and MKR WiFi 1010 can also be used. Both regular and enterprise authentication are also supported.
If you are interested in guest authentication, check out my desktop dashboard that programmatically clicks the "I accept terms and conditions" and (simulates) pressing enter
to connect to internet.
Guest authentication is not (yet) implemented here.
Clone this repo to your local drive (typically in the c:\workspace
directory for Windows users):
c:
mkdir -p c:\workspace
cd workspace
git clone https://github.com/gojimmypi/RFID_Logger.git
Edit the GlobalDefine.h
file, and create/edit your own myPrivateSettings.h
file:
#define USE_myPrivateSettings true
#if USE_myPrivateSettings == true
#include "/workspace-git/myPrivateSettings.h"
#else
... your settings here for USE_myPrivateSettings == false, or copy example settings to your own myPrivateSettings.h
It is not recommended to set USE_myPrivateSettings == false
, as it is usually best to keep your passwords and private settings someplace that will not be
inadvertantly saved to GitHub. But yes, you can set this and edit the settings directly in the GlobalDefine.h
file.
The code is Arduino-style C created in Visual Studio using the Visual Micro Extension; see also the Arduino IDE for Visual Studio (Visual Micro) on the marketplace. It should also work just fine in the Arduino IDE (see the RFID_Logger.ino file)
Check the the proper board is selected (e.g. ESP32 WROVER
for the ThingPulse board), and the appropriate settings for either environment:
Install the Visual Micro IDE Extension, if needed.
Open RFID_Logger.sln
in Visual Studio. Check settings and select your COM port:
Open RFID_Logger.ino
in the Arduino IDE. Check settings and select your COM port:
Any Arduino-style device with Wi-Fi and SPI capabilities could probably be used; at this time both the ESP8266 and ESP32 are supported, as well as the Ardunio MKR WiFi 1010, using either regular or enterprise Wi-Fi, and communicating over SSL.
The main app sits in an infinite loop awaiting a card to be detected. See the WiFi Helper for connection to WiFi. There's an IIS Web App for listening for inbound data. Data is saved in a SQL Table by a stored procedure called from the web page.
With Enterprise Security at the WiFi AP, integrated security could be configured at the web server.
Why not a Raspberry Pi? The only thing we are doing is sending an RFID value to a database. Yes, the implementation would probably be easier on a Raspberry Pi. But we don't need the complexity and vulerabilities of an entire operating system. An embedded controller is also vastly more appropriate for low power applications.
This solution should NOT be used for security applications, as noted here and repeated here:
-
The UID of a card can not be used as an unique identification for security related projects. Some cards allow the UID to be changed - which means you can easily clone a card. For projects like access control, door opener or payment systems you must implement an additional security mechanism like a password or normal key.
-
This library only supports crypto1-encrypted communication. Crypto1 has been known as broken for a few years, so it does NOT offer ANY security, it is virtually unencrypted communication. Do not use it for any security related applications!
-
This library does not offer 3DES or AES authentication used by cards like the Mifare DESFire, it may be possible to be implemented because the datasheet says there is support. We hope for pull requests :).
This section applied to both Visual Micro and the Arduino IDE as Visual Micro uses the same settings and library paths as the Arduino IDE.
In the Arduino IDE, under File
- Prewferences
, enter a comma-delimited Additional Boards Manager URL
such as these two for the ESP8266 and ESP32:
https://arduino.esp8266.com/stable/package_esp8266com_index.json,https://dl.espressif.com/dl/package_esp32_index.json
Unfortunately, the D1 LED on the blue version of the board is a straight 10K power to ground as shown on the schematic. This LED drops about 1.8v so we have (3.3 - 1.8) / 10,000 = 0.15mA (150 microamps) wasted on a power indicator we can't even control. Ok, this is not a lot. On battery, every microamp counts. The entire RFID board consumes just under 10mA during normal operation (9.67mA measured).
See section 8.6 Power reduction modes
(page 33) of the MFRC522 data sheet and TODO...
There's a SunFounder Mifare RC522 Card Reader that is more expensive, but appears to not have the LED. The wiki claims the idle current is still 10-13mA.
- ePulse – Low Power ESP32 development board
- Mifare RC522 RF IC Card Sensor Module
- Project Enclosure (consider getting something with mounting ears if needed, and if you need room for a battery)
- 13.56MHz RFID Access Control such as these read-only Keyfobs, or these Rewritable ones ones, smart cards such as these.
- internal mounting hardware: platic screws, ziptie, foam to insulate boards to avoid touching each other.
This code is not compatible with the PN532 NFC/RFID technology, such as the Adafruit PN532
Although they may look similar, this solution does not work with 125kHz RFID Key Fobs.
- Make sure firewall port 443 is open on target system for the Wi-Fi IP address of your device. (beware DHCP addresses can change over time)
- Check to see if any other program is using the COM port (Other instances of Visual Studio, Arduino IDE Serial Monitor, putty sessions, VM connections, etc.)
- See miguelbalboa/rfid
I'd like to thank:
- Dani for all the creative ideas exchanged via DM
- Martin for all the great RFID code examples
- Espressif for a simply amazing, low cost embedded controller: the ESP32
Essentials:
- ePulse – Low Power ESP32 development board
- Easy EDA RFID MFRC522
- Visual Micro Arduino IDE for Visual Studio
- ESP8266 Install / Boards Manager
MKR WiFi 1010
Code samples:
- espressif/arduino-esp32 WiFiClientSecureEnterprise.ino example
- martinius96/ESP32-eduroam (excellent place to get started; many examples)
- Using a MFRC522 reader to read and write MIFARE RFID cards on ARDUINO through the MFRC522 library BY COOQROBOT
- JeroenBeemster ESP32 WPA2 Enterprise example simplified for Arduino
- esp8266wifi client secure examples
- espressif/arduino-esp32: Is it possible to connect to WPA2 Enterprise with Arduino IDE #160
- esp8266/Arduino/libraries/ESP8266WiFi/src/
- esp8266/Arduino/tools/sdk/include/wpa2_enterprise.h
WiFi:
HTTP:
RFID:
Power Related:
- ePulse – Low Power ESP32 development board
- blog.squix ESP32 Low Power Device Design – Part 1
- Nordic ID: How Different Power Saving Options Affect Your RFID Reader’s Battery Life and Power Consumption
- Random Nerd Tutorials: ESP32 External Wake Up from Deep Sleep
- miguelbalboa/rfid/issues/269 - Power Down Modes
GitHub Issues:
- esp8266/Arduino WPA2 enterprise with credentials auth ok with radius but still get STATION_WRONG_PASSWORD after 30s #6803
- espressif/arduino-esp32 WifiClientSecure connect(IPAddress ip, hostport) not working #1487
- espressif/arduino-esp32 Cannot enable WPA2 Enterprise using arduino libraries #1744
- JeroenBeemster/ESP32-WPA2-enterprise sp_wifi_sta_wpa2_ent_enable() needs a parameters #3
Other stuff: