paulo-raca / YetAnotherArduinoWiegandLibrary

Event-driven Wiegand Library for Arduino
The Unlicense
68 stars 28 forks source link

How to make a Wiegand Keypad work ? #33

Closed MetriciRO closed 1 year ago

MetriciRO commented 1 year ago

I am working with the Interrupt example on an ESP32 and I have no idea how to make a Wiegand Keypad work.

If I set wiegand.begin(26, true); and press on the keypad I get the Card read error: Message size unexpected - Raw data: 8bits error and the 8bit raw data of each key, which I guess is HEX:

1 = E1; 2 = D2; 3 = C3; 
4 = B4; 5 =A5 ; 6 = 96; 
7 = 87; 8 = 78; 9 = 69; 
* = 5A; 0 = F0; # = 4B; 

If I set wiegand.begin(Wiegand::LENGTH_ANY, true); and press on the keypad I get nothing. No reads, no messages, no errors.

void IRAM_ATTR receivedData(uint8_t *data, uint8_t bits, const char *message)
{
    uint8_t bytes = (bits + 7) / 8;
    // Wiegand 26, first and last bits are for control, remaining 24 bits
    if (bits == 24)
    {
        wiegandFacilityCode = String(data[0] >> 4, 16) + String(data[0] & 0xF, 16);
        wiegandCardNumber = "";

        for (int i = 1; i < bytes; i++)
        {
            wiegandCardNumber += String(data[i] >> 4, 16);
            wiegandCardNumber += String(data[i] & 0xF, 16);
        }
        didReadWiegandCard = true;
    }
}

// Notifies when an invalid transmission is detected
void receivedDataError(Wiegand::DataError error, uint8_t *rawData, uint8_t rawBits, const char *message)
{
    Serial.print(message);
    Serial.print(Wiegand::DataErrorStr(error));
    Serial.print(" - Raw data: ");
    Serial.print(rawBits);
    Serial.print("bits / ");

    // Print value in HEX
    uint8_t bytes = (rawBits + 7) / 8;
    for (int i = 0; i < bytes; i++)
    {
        Serial.print(rawData[i] >> 4, 16);
        Serial.print(rawData[i] & 0xF, 16);
    }
    Serial.println();
}
paulo-raca commented 1 year ago

Hello, @MetriciRO

Keypads are usually sent in 4 or 8 bit messages, and from the code you sent it looks like you are ignoring anything but 26 bits.

MetriciRO commented 1 year ago

Hello, @MetriciRO

Keypads are usually sent in 4 or 8 bit messages, and from the code you sent it looks like you are ignoring anything but 26 bits.

You are right. I've made it work. Thank you.