Skip to main content

Keypad Widget

⚡ Control

The Keypad widget presents a numeric 0–9 pad with a send (✓) and clear (✗) button. Digits are hidden as they are typed. The completed entry is sent as a single string when the user confirms. Use it for door locks, alarm codes, or authenticated commands.

Default size: 2 × 3 grid cells


Configuration

PropertyTypeDefaultDescription
pinLengthnumber4Expected PIN length (auto-sends when reached)
autoSendbooleantrueSend immediately when pinLength digits entered
DevicedeviceThe device to write to
PinV0V255The virtual pin to write
LabelstringWidget label

Firmware example

const String MASTER_PIN = "1234";

VWIRE_RECEIVE(V0) {
String entered = param.asStr();

if (entered == MASTER_PIN) {
unlockDoor();
Vwire.virtualSend(V0, "UNLOCKED");
} else {
Vwire.virtualSend(V0, "DENIED");
delay(3000); // lockout
lockDoor();
}
// Clear display after 3 s
delay(3000);
Vwire.virtualSend(V0, "");
}

Lockout pattern

Add failed-attempt lockout on the device side:

int failCount = 0;

VWIRE_RECEIVE(V0) {
String entered = param.asStr();

if (failCount >= 3) {
Vwire.virtualSend(V0, "LOCKED 30s");
return; // ignore until timeout resets failCount
}

if (entered == MASTER_PIN) {
failCount = 0;
unlockDoor();
Vwire.virtualSend(V0, "UNLOCKED");
} else {
failCount++;
Vwire.virtualSend(V0, "DENIED (" + String(3 - failCount) + " left)");
}
}

Security note

PIN storage

Never hard-code PINs in firmware for production. Store PINs in NVS / flash with encryption, or validate against a server-side hash. The Keypad widget sends the raw PIN string — use TLS (MQTTS) to protect it in transit, which VWire does by default.