28#include <ArduinoJson.h>
40constexpr char WIFI_PASS[] =
"mrbombasticcallmefantastic";
141void callback(
char* topic,
byte* payload,
unsigned int length) {
144 if (length == 0)
return;
146 StaticJsonDocument<512> doc;
149 DeserializationError err = deserializeJson(doc, payload, length);
153 Serial.print(
"JSON parse failed: ");
154 Serial.println(err.c_str());
161 if (strcmp(topic,
net.makeTopic(
"access/response").c_str()) == 0) {
164 kpEnabled = (doc[
"response"][
"hasAccess"] |
false)
171 else if (strcmp(topic,
net.makeTopic(
"access/keypad_response").c_str()) == 0) {
189 Serial.begin(115200);
202 Serial.println(
"Keypad + MQTT ready");
207 Serial.printf(
"access/response MQTT subscribe %s\n",
208 net.subscribe(
net.makeTopic(
"access/response").c_str()) ?
"OK" :
"FAILED");
210 Serial.printf(
"access/keypad_response MQTT subscribe %s\n",
211 net.subscribe(
net.makeTopic(
"access/keypad_response").c_str()) ?
"OK" :
"FAILED");
236 StaticJsonDocument<64> data;
237 data[
"event"] =
"KP_tap";
240 net.publishJson(
"keypad/tap", data);
261 char key =
keypad.getKey();
271 if (key >=
'0' && key <=
'9') {
278 Serial.print(
"Key: ");
286 else if (key ==
'#') {
290 Serial.print(
"Submitting code: ");
291 Serial.println(
input);
294 StaticJsonDocument<64> data;
295 data[
"event"] =
"KP_try";
296 data[
"code"] =
input;
298 net.publishJson(
"keypad/submit", data);
301 Serial.println(
"Code too short, resetting.");
311 else if (key ==
'*') {
313 Serial.println(
"Input cleared");
Lightweight WiFi + MQTT helper wrapper for ESP-based Arduino systems.
Combined WiFi and MQTT client abstraction.
constexpr char WIFI_PASS[]
WiFi password.
constexpr char DEVICE_ID[]
Unique device identifier used in MQTT topics.
WifiMqttClient net
WiFi + MQTT client wrapper.
constexpr char MQTT_USER[]
MQTT username.
constexpr char MQTT_PASS[]
MQTT password.
constexpr char MQTT_HOST[]
MQTT broker hostname.
constexpr uint16_t MQTT_PORT
MQTT broker port.
void callback(char *topic, byte *payload, unsigned int length)
MQTT message callback handler.
constexpr char WIFI_SSID[]
WiFi SSID.
Keypad keypad
Keypad instance handling scanning and debouncing.
bool kpEnabled
Indicates whether keypad input is currently enabled.
void setup()
Arduino setup function.
byte rowPins[ROWS]
GPIO pins connected to keypad rows.
constexpr uint8_t CODE_LENGTH
Required PIN length.
const byte ROWS
Number of rows in the keypad matrix.
char keys[ROWS][COLS]
Logical keypad layout.
void reset_code()
Resets the PIN input buffer and index.
byte colPins[COLS]
GPIO pins connected to keypad columns.
char input[CODE_LENGTH+1]
Input buffer for PIN digits.
void callback(char *topic, byte *payload, unsigned int length)
MQTT message callback handler.
void publishTap()
Publishes keypad tap feedback via MQTT.
const byte COLS
Number of columns in the keypad matrix.
void loop()
Arduino main loop.
uint8_t currentIdx
Current index into the PIN buffer.