ESP8266 Door Access Control System
Loading...
Searching...
No Matches
ESP2 - Keypad

Functions

void callback (char *topic, byte *payload, unsigned int length)
 MQTT message callback handler.
void setup ()
 Arduino setup function.
void reset_code ()
 Resets the PIN input buffer and index.
void publishTap ()
 Publishes keypad tap feedback via MQTT.
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.
const byte ROWS = 4
 Number of rows in the keypad matrix.
const byte COLS = 4
 Number of columns in the keypad matrix.
char keys [ROWS][COLS]
 Logical keypad layout.
byte rowPins [ROWS] = {16, 5, 4, 0}
 GPIO pins connected to keypad rows.
byte colPins [COLS] = {2, 14, 12, 13}
 GPIO pins connected to keypad columns.
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS)
 Keypad instance handling scanning and debouncing.
constexpr uint8_t CODE_LENGTH = 4
 Required PIN length.
char input [CODE_LENGTH+1] = {0}
 Input buffer for PIN digits.
uint8_t currentIdx = 0
 Current index into the PIN buffer.
bool kpEnabled = false
 Indicates whether keypad input is currently enabled.

Detailed Description

This firmware runs on an ESP-based Arduino-compatible board and implements the second stage of the access control system.

Hardware components:

  • 4x4 matrix keypad using the Keypad library

Functional responsibilities:

  • Accepts PIN input from the user
  • Provides keypress feedback (beeps)
  • Publishes PIN entry progress and submissions via MQTT

The keypad is only active after successful RFID authentication, which is signaled asynchronously via MQTT.

Function Documentation

◆ callback()

void callback ( char * topic,
byte * payload,
unsigned int length )

MQTT message callback handler.

Handles:

  • Enabling keypad input after RFID access is granted
  • Disabling keypad input after PIN validation completes
Parameters
topicMQTT topic string.
payloadRaw payload bytes.
lengthPayload length.

Definition at line 141 of file esp2_keypad.ino.

◆ loop()

void loop ( )

Arduino main loop.

Handles:

  • MQTT client processing
  • Keypad scanning
  • PIN entry logic
  • PIN submission and reset

Definition at line 256 of file esp2_keypad.ino.

Here is the call graph for this function:

◆ publishTap()

void publishTap ( )

Publishes keypad tap feedback via MQTT.

Sends the current PIN length after each valid keypress, allowing external systems to provide visual or audio feedback.

Definition at line 235 of file esp2_keypad.ino.

Here is the caller graph for this function:

◆ reset_code()

void reset_code ( )

Resets the PIN input buffer and index.

Clears any partially entered PIN and prepares the buffer for new input.

Definition at line 224 of file esp2_keypad.ino.

Here is the caller graph for this function:

◆ setup()

void setup ( )

Arduino setup function.

Initializes Serial output, WiFi connection, MQTT client, and topic subscriptions.

Definition at line 188 of file esp2_keypad.ino.

Here is the call graph for this function:

Variable Documentation

◆ CODE_LENGTH

uint8_t CODE_LENGTH = 4
constexpr

Required PIN length.

Definition at line 107 of file esp2_keypad.ino.

◆ colPins

byte colPins[COLS] = {2, 14, 12, 13}

GPIO pins connected to keypad columns.

Order must match COLS definition. D4, D5, D6, D7

Definition at line 87 of file esp2_keypad.ino.

◆ COLS

const byte COLS = 4

Number of columns in the keypad matrix.

Definition at line 60 of file esp2_keypad.ino.

◆ currentIdx

uint8_t currentIdx = 0

Current index into the PIN buffer.

Definition at line 117 of file esp2_keypad.ino.

◆ DEVICE_ID

char DEVICE_ID[] = "door1"
constexpr

Unique device identifier used in MQTT topics.

Definition at line 52 of file esp2_keypad.ino.

◆ input

char input[CODE_LENGTH+1] = {0}

Input buffer for PIN digits.

One extra byte is reserved for the null terminator.

Definition at line 114 of file esp2_keypad.ino.

◆ keypad

Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS)

Keypad instance handling scanning and debouncing.

Definition at line 102 of file esp2_keypad.ino.

◆ keys

char keys[ROWS][COLS]
Initial value:
= {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
}

Logical keypad layout.

Defines the character returned for each row/column intersection.

Definition at line 67 of file esp2_keypad.ino.

◆ kpEnabled

bool kpEnabled = false

Indicates whether keypad input is currently enabled.

This flag is controlled via MQTT messages from the access controller.

Definition at line 124 of file esp2_keypad.ino.

◆ MQTT_HOST

char MQTT_HOST[] = "maqiatto.com"
constexpr

MQTT broker hostname.

Definition at line 43 of file esp2_keypad.ino.

◆ MQTT_PASS

char MQTT_PASS[] = "potter"
constexpr

MQTT password.

Definition at line 49 of file esp2_keypad.ino.

◆ MQTT_PORT

uint16_t MQTT_PORT = 1883
constexpr

MQTT broker port.

Definition at line 45 of file esp2_keypad.ino.

◆ MQTT_USER

char MQTT_USER[] = "hectorfoss@gmail.com"
constexpr

MQTT username.

Definition at line 47 of file esp2_keypad.ino.

◆ net

WiFi + MQTT client wrapper.

Definition at line 35 of file esp2_keypad.ino.

◆ rowPins

byte rowPins[ROWS] = {16, 5, 4, 0}

GPIO pins connected to keypad rows.

Order must match ROWS definition. D0, D1, D2, D3

Definition at line 80 of file esp2_keypad.ino.

◆ ROWS

const byte ROWS = 4

Number of rows in the keypad matrix.

Definition at line 57 of file esp2_keypad.ino.

◆ WIFI_PASS

char WIFI_PASS[] = "mrbombasticcallmefantastic"
constexpr

WiFi password.

Definition at line 40 of file esp2_keypad.ino.

◆ WIFI_SSID

char WIFI_SSID[] = "Mathias2.4"
constexpr

WiFi SSID.

Definition at line 38 of file esp2_keypad.ino.