|
ESP8266 Door Access Control System
|
Enumerations | |
| enum class | AccessResult : uint8_t { AccessResult::Denied , AccessResult::Granted , AccessResult::Denied , AccessResult::Granted } |
| Access result enumeration. More... | |
Functions | |
| MFRC522 | mfrc522 (RFID_SS_PIN, RFID_RST_PIN) |
| MFRC522 RFID reader instance. | |
| LiquidCrystal_I2C | lcd (LCD_ADDRESS, LCD_COLUMNS, LCD_ROWS) |
| I2C LCD instance. | |
| void | lcdPrintLine (const __FlashStringHelper *msg, uint8_t line) |
| Clears an LCD line and prints a flash-resident string. | |
| void | lcdPrintLine (const char *msg, uint8_t line) |
| Clears an LCD line and prints a RAM-resident string. | |
| static void | forceLock () |
| Forces the system back into locked idle state. | |
| void | makeEnteredPins (uint8_t pinLength) |
| Builds a masked PIN string for LCD display. | |
| void | callback (char *topic, byte *payload, unsigned int length) |
| MQTT message callback handler. | |
| bool | isDisplayActive (uint32_t now) |
| Checks whether the LCD backlight should remain active. | |
| void | onMotionDetected (uint32_t now) |
| Handles motion-detected events. | |
| void | onMotionIdle (uint32_t now) |
| Handles motion-idle state. | |
| void | updateMotionState (uint32_t now) |
| Updates motion state based on PIR sensor input. | |
| void | uidToHexString (const MFRC522::Uid &uid, char *output, size_t outputSize) |
| Converts an RFID UID to a hexadecimal string. | |
| void | handleRFID () |
| Handles RFID card detection and request publishing. | |
| void | setup () |
| Arduino setup function. | |
| void | loop () |
| Arduino main loop. | |
Variables | |
| WifiMqttClient | net |
| WiFi + MQTT client wrapper. | |
| constexpr char | WIFI_SSID [] = "Mathias2.4" |
| WiFi SSID. | |
| constexpr char | WIFI_PASS [] = "mrbombasticcallmefantastic" |
| WiFi password. | |
| constexpr char | MQTT_HOST [] = "maqiatto.com" |
| MQTT broker hostname. | |
| constexpr uint16_t | MQTT_PORT = 1883 |
| MQTT broker port. | |
| constexpr char | MQTT_USER [] = "hectorfoss@gmail.com" |
| MQTT username. | |
| constexpr char | MQTT_PASS [] = "potter" |
| MQTT password. | |
| constexpr char | DEVICE_ID [] = "door1" |
| Unique device identifier used in MQTT topics. | |
| constexpr uint8_t | RFID_SS_PIN = 15 |
| RC522 SPI Slave Select pin (D8 / GPIO15). | |
| constexpr uint8_t | RFID_RST_PIN = 16 |
| RC522 Reset pin (D0 / GPIO16). | |
| constexpr uint8_t | MOTION_PIN = 0 |
| Motion sensor pin (D3 / GPIO0). | |
| constexpr uint8_t | I2C_SDA_PIN = 4 |
| I2C SDA pin for LCD (D2 / GPIO4). | |
| constexpr uint8_t | I2C_SCL_PIN = 5 |
| I2C SCL pin for LCD (D1 / GPIO5). | |
| constexpr uint8_t | LCD_COLUMNS = 16 |
| Number of LCD columns. | |
| constexpr uint8_t | LCD_ROWS = 2 |
| Number of LCD rows. | |
| constexpr uint8_t | LCD_ADDRESS = 0x27 |
| I2C address of the LCD module. | |
| constexpr uint32_t | DISPLAY_MS = 3000 |
| Duration (ms) to display text before resetting. | |
| constexpr uint32_t | DISPLAY_BACKLIGHT_MS = 5000 |
| Duration (ms) to keep LCD backlight on after motion. | |
| constexpr uint32_t | PIN_TIME_MS = 15000 |
| Time window (ms) for entering PIN after RFID success. | |
| constexpr uint32_t | UNLOCK_TIME_MS = 5000 |
| Door unlock display duration (ms). | |
| constexpr uint32_t | POLL_MS = 30 |
| Main loop polling delay (ms). | |
| AccessResult | rfidAccess |
| Result of RFID authentication. | |
| AccessResult | accessGranted |
| Result of PIN verification. | |
| bool | textshown = false |
| Indicates whether a status message is currently displayed. | |
| uint32_t | showTextUntil = 0 |
| Timestamp (ms) when the displayed text should expire. | |
| uint32_t | showDisplayUntil = 0 |
| Timestamp (ms) when LCD backlight should turn off. | |
| bool | motionActive = false |
| Indicates whether motion is currently considered active. | |
| static char | enteredPins [5] = " " |
| Masked PIN buffer shown on LCD (max 4 digits + null terminator). | |
This firmware runs on an ESP-based Arduino-compatible board and implements the first stage of a distributed door access control system.
Hardware components:
Functional responsibilities:
RFID authentication must succeed before the keypad stage is enabled.
|
strong |
Access result enumeration.
| Enumerator | |
|---|---|
| Denied | Access denied |
| Granted | Access granted |
| Denied | Access denied |
| Granted | Access granted |
Definition at line 130 of file esp1_rfid_motion.ino.
| void callback | ( | char * | topic, |
| byte * | payload, | ||
| unsigned int | length ) |
MQTT message callback handler.
Parses incoming JSON messages and dispatches logic based on topic:
| topic | MQTT topic string. |
| payload | Raw payload bytes. |
| length | Payload length. |
Definition at line 240 of file esp1_rfid_motion.ino.
|
static |
Forces the system back into locked idle state.
Resets access state, clears temporary flags, and restores the default idle LCD message.
Definition at line 196 of file esp1_rfid_motion.ino.
| void handleRFID | ( | ) |
Handles RFID card detection and request publishing.
Detects new cards, reads UID, updates LCD, and sends an MQTT access request.
Definition at line 440 of file esp1_rfid_motion.ino.
| bool isDisplayActive | ( | uint32_t | now | ) |
Checks whether the LCD backlight should remain active.
Uses signed time comparison to safely handle millis() wraparound.
| now | Current time in milliseconds. |
Definition at line 353 of file esp1_rfid_motion.ino.
| LiquidCrystal_I2C lcd | ( | LCD_ADDRESS | , |
| LCD_COLUMNS | , | ||
| LCD_ROWS | ) |
I2C LCD instance.
| void lcdPrintLine | ( | const __FlashStringHelper * | msg, |
| uint8_t | line ) |
Clears an LCD line and prints a flash-resident string.
| msg | Flash string (use F("...")). |
| line | LCD row index. |
Definition at line 170 of file esp1_rfid_motion.ino.
| void lcdPrintLine | ( | const char * | msg, |
| uint8_t | line ) |
Clears an LCD line and prints a RAM-resident string.
| msg | C-string to print. |
| line | LCD row index. |
Definition at line 183 of file esp1_rfid_motion.ino.
| void loop | ( | ) |
Arduino main loop.
Executes non-blocking system logic:
Definition at line 536 of file esp1_rfid_motion.ino.
| void makeEnteredPins | ( | uint8_t | pinLength | ) |
Builds a masked PIN string for LCD display.
Converts a numeric PIN length into a visual representation using '*' characters and trailing spaces.
| pinLength | Number of digits entered so far. |
Definition at line 211 of file esp1_rfid_motion.ino.
| MFRC522 mfrc522 | ( | RFID_SS_PIN | , |
| RFID_RST_PIN | ) |
MFRC522 RFID reader instance.
| void onMotionDetected | ( | uint32_t | now | ) |
Handles motion-detected events.
Activates LCD backlight and refreshes display timeout.
| now | Current time in milliseconds. |
Definition at line 364 of file esp1_rfid_motion.ino.
| void onMotionIdle | ( | uint32_t | now | ) |
Handles motion-idle state.
Turns off LCD backlight when motion has ceased and the timeout has expired.
| now | Current time in milliseconds. |
Definition at line 383 of file esp1_rfid_motion.ino.
| void setup | ( | ) |
Arduino setup function.
Initializes hardware peripherals, LCD, WiFi, MQTT client, and topic subscriptions.
Definition at line 481 of file esp1_rfid_motion.ino.
| void uidToHexString | ( | const MFRC522::Uid & | uid, |
| char * | output, | ||
| size_t | outputSize ) |
Converts an RFID UID to a hexadecimal string.
Each UID byte is encoded as two uppercase hexadecimal characters.
| uid | MFRC522 UID structure. |
| output | Destination buffer. |
| outputSize | Size of destination buffer. |
Definition at line 416 of file esp1_rfid_motion.ino.
| void updateMotionState | ( | uint32_t | now | ) |
Updates motion state based on PIR sensor input.
Dispatches to motion-detected or motion-idle handlers.
| now | Current time in milliseconds. |
Definition at line 397 of file esp1_rfid_motion.ino.
| AccessResult accessGranted |
Result of PIN verification.
Definition at line 139 of file esp1_rfid_motion.ino.
|
constexpr |
Unique device identifier used in MQTT topics.
Definition at line 60 of file esp1_rfid_motion.ino.
|
constexpr |
Duration (ms) to keep LCD backlight on after motion.
Definition at line 102 of file esp1_rfid_motion.ino.
|
constexpr |
Duration (ms) to display text before resetting.
Definition at line 99 of file esp1_rfid_motion.ino.
|
static |
Masked PIN buffer shown on LCD (max 4 digits + null terminator).
Filled with '*' for entered digits and spaces for remaining slots.
Definition at line 158 of file esp1_rfid_motion.ino.
|
constexpr |
I2C SCL pin for LCD (D1 / GPIO5).
Definition at line 79 of file esp1_rfid_motion.ino.
|
constexpr |
I2C SDA pin for LCD (D2 / GPIO4).
Definition at line 76 of file esp1_rfid_motion.ino.
|
constexpr |
I2C address of the LCD module.
Definition at line 92 of file esp1_rfid_motion.ino.
|
constexpr |
Number of LCD columns.
Definition at line 86 of file esp1_rfid_motion.ino.
|
constexpr |
Number of LCD rows.
Definition at line 89 of file esp1_rfid_motion.ino.
|
constexpr |
Motion sensor pin (D3 / GPIO0).
Definition at line 73 of file esp1_rfid_motion.ino.
| bool motionActive = false |
Indicates whether motion is currently considered active.
Definition at line 151 of file esp1_rfid_motion.ino.
|
constexpr |
MQTT broker hostname.
Definition at line 51 of file esp1_rfid_motion.ino.
|
constexpr |
MQTT password.
Definition at line 57 of file esp1_rfid_motion.ino.
|
constexpr |
MQTT broker port.
Definition at line 53 of file esp1_rfid_motion.ino.
|
constexpr |
MQTT username.
Definition at line 55 of file esp1_rfid_motion.ino.
| WifiMqttClient net |
WiFi + MQTT client wrapper.
Definition at line 43 of file esp1_rfid_motion.ino.
|
constexpr |
Time window (ms) for entering PIN after RFID success.
Definition at line 105 of file esp1_rfid_motion.ino.
|
constexpr |
Main loop polling delay (ms).
Definition at line 111 of file esp1_rfid_motion.ino.
|
constexpr |
RC522 Reset pin (D0 / GPIO16).
Definition at line 70 of file esp1_rfid_motion.ino.
|
constexpr |
RC522 SPI Slave Select pin (D8 / GPIO15).
Definition at line 67 of file esp1_rfid_motion.ino.
| AccessResult rfidAccess |
Result of RFID authentication.
Definition at line 136 of file esp1_rfid_motion.ino.
| uint32_t showDisplayUntil = 0 |
Timestamp (ms) when LCD backlight should turn off.
Definition at line 148 of file esp1_rfid_motion.ino.
| uint32_t showTextUntil = 0 |
Timestamp (ms) when the displayed text should expire.
Definition at line 145 of file esp1_rfid_motion.ino.
| bool textshown = false |
Indicates whether a status message is currently displayed.
Definition at line 142 of file esp1_rfid_motion.ino.
|
constexpr |
Door unlock display duration (ms).
Definition at line 108 of file esp1_rfid_motion.ino.
|
constexpr |
WiFi password.
Definition at line 48 of file esp1_rfid_motion.ino.
|
constexpr |
WiFi SSID.
Definition at line 46 of file esp1_rfid_motion.ino.