monkeyboard / Wiegand-Protocol-Library-for-Arduino

Wiegand 26 and Wiegand 34 Protocol Library for Arduino
323 stars 131 forks source link

Wiegand 32 wrong output #58

Open pasleto opened 2 years ago

pasleto commented 2 years ago

Hello,

i have Mifare card with UID A4DCCC1D.

When reading with Wiegand reader using Wiegand 32 Type with this code i get this: HEX = 126E660E, DECIMAL = 309224974, Wiegand Type = W32

The code is not the same as expected, it seems this library shift binary data off somehow:

A4DCCC1D To Binary Converted 10100100110111001100110000011101 126E660E To Binary Converted 00010010011011100110011000001110

-10100100110111001100110000011101 <- Mifare UID (HEX = A4DCCC1D | DECIMAL = 2765933597) 00010010011011100110011000001110- <- Wiegand 32 (HEX = 126E660E | DECIMAL = 309224974)

How to solve this issue?

jpliew commented 2 years ago

Hi @pasleto

The values are correct.

In Wiegand standard, most significant bit and least significant bit are both parity check. They are not the ID of the card.

10100100110111001100110000011101   --> A4DCCC1D from your card
 010010011011100110011000001110    --> from Wiegand library 126E660E after taken out the most and least significant bits

When you align the bits together like above, they are exactly the same.

There are two ways you can resolve this

  1. Follow the Wiegand standard and remove the parity bits, just like this library does
  2. Not follow the Wiegand standard and change the line https://github.com/monkeyboard/Wiegand-Protocol-Library-for-Arduino/blob/2a702d7befd6d906d1663481fe6d99415f37526c/src/Wiegand.cpp#L112 and disable the parity removal.

Hope this helps.

pasleto commented 2 years ago

Hi @jpliew, thanks for reply.

A4DCCC1D is card UID, which i need to read exactly as it is. First and last parity bits are correct when using WG34 -> outputs 32-bit card UID But my reader outputs 32-bit without parity bits, so this code strip it into 30-bit data.

I tried to modify (codelow & 0x7FFFFFFE ) >>1; to codelow, but it returned 24DCCC1D.

jpliew commented 2 years ago

@pasleto

Your reader is outputting W32

2 parity bits + 30 data bit.

To proof what I said, you can try this library https://github.com/jpliew/Wiegand-NG-Multi-Bit-Wiegand-Library-for-Arduino

It will print the RAW data without modification.

pasleto commented 2 years ago

I tried NG library aswell, it outputs data as expected in binary format.

But can't figure out how to get the output in hex.

jpliew commented 2 years ago

@pasleto your reader should output W34 with the parity bits. That way the library will be able to read W34 and give you the correct 32 bit data of the card.

If you can configure the reader to send out W34 with parity in it, this will fix your problem.

If not then you might want to use WiegandNG library and figure out how to convert the binary data to hex.

pasleto commented 2 years ago

Yeah, the reader supports multiple Wiegand outputs (26,32,34,37,40,56,64).

I need modular solution for Wiegand from 32 bits up to 64 bits, so I will use NG library and modify the output somehow.