Skip to content

How to capture and store read card data ? Using String produces read errors. #30

@ghost

Description

I have a modified Interrupts sketch uploaded on an ESP32-EVB which is connected to a Bosch ARD-AYK12 - RFID Proximity Reader.

When using this modified receivedData function I get reading errors:

void receivedData(uint8_t *data, uint8_t bits, const char *message)
{
    uint8_t bytes = (bits + 7) / 8;
    String hexa = "";
    for (int i = 0; i < bytes; i++)
    {
        hexa += String(data[i] >> 4, 16);
        hexa += String(data[i] & 0xF, 16);
    }
    
    hexa.toUpperCase();
    Serial.println(hexa);

    String wiegand_msg = "";
    wiegand_msg += String(message);
    wiegand_msg += String(bits);
    wiegand_msg += String("bits / HEX: ");
    // Print value in HEX
    wiegand_msg += hexa + " / DEC: " + String(fromHexToDec(hexa));
    // Wiegand 26, first and last bits are for control, remaining 24 bits
    if (bits == 24)
    {
        String c1 = String(data[0] >> 4, 16) + String(data[0] & 0xF, 16);
        String c2 = "";

        for (int i = 1; i < bytes; i++)
        {
            c2 += String(data[i] >> 4, 16);
            c2 += String(data[i] & 0xF, 16);
        }
        wiegand_msg += " / Facility Code: " + fromHexToDec(c1);
        wiegand_msg += " / Card Number: " + fromHexToDec(c2);

        logOutput(wiegand_msg);

        wiegandCardDec = fromHexToDec(c2);
        while (wiegandCardDec.length() < 10)
        {
            wiegandCardDec = String(0) + wiegandCardDec;
        }
        Serial.println("Wiegand Card: " + wiegandCardDec);
        didReadWiegandCard = true;
    }
}

Here is a Serial output while reading two card:

Card read error: Unsupported message formatUnsupported message format - Raw data: 25bits / 003EE19F
1F70CF
Card read: 24bits / HEX: 1F70CF / DEC: 2060495 / Facility Code: 31 / Card Number: 28879
Wiegand Card: 0000028879
1F70CF
Card read: 24bits / HEX: 1F70CF / DEC: 2060495 / Facility Code: 31 / Card Number: 28879
Wiegand Card: 0000028879
1F70CF
Card read: 24bits / HEX: 1F70CF / DEC: 2060495 / Facility Code: 31 / Card Number: 28879
Wiegand Card: 0000028879
0D9030
Card read: 24bits / HEX: 0D9030 / DEC: 888880 / Facility Code: 13 / Card Number: 36912
Wiegand Card: 0000036912

I need to get the card number as decimal, but adding code inside receivedData make it unstable it seems.

There are similar issues to mine with no apparent fix:
#22
#13
#12

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions