Hauptmenü

RFID Module

Begonnen von andrejs, 25 April 2014, 17:15:25

Vorheriges Thema - Nächstes Thema

andrejs

I created my first module 99_RFID.pm for reading the data from USB RFID Reader 125 kHz (bought on Ebay http://www.ebay.com/itm/USB-RFID-Contactless-Proximity-Security-Sensor-Smart-Card-Reader-125Khz-EM4100-/360838251721?pt=BI_Security_Fire_Protection&hash=item5403a2c4c9). The module was not created from scratch because I used the existing one created by R.Koenig (thank you for that) and make some changes.
In order to connect RFID READER to FHEM you should do the following:
•   Do not use USB port on the USB Reader for the connection but open the plastic box of the reader and connect wires on the pins on PCB. The instructions can be find in German language http://www.pcmx.de/?p=216
•   For the connection from pins on PCB to the USB of the computer I used the USB 2.0 to UART TTL 6PIN Connector Module (bought on Ebay)

Description of the perl module

Define
Define <name> RFID  <subtype> <devicename> <card number> <keylock>
<subtype> can be "user" or "system"
<devicename> specifies the serial port to communicate with the RFID Reader. The name of the serial-device depends on your distribution, under linux the cdc_acm kernel module is responsible, and usually a /dev/ttyACM0 device will be created.
<card number> should defined if subtype is "user". Card number is a 10 digit number which is normally printed on RFID key or card.
<keylock> should be defined if subtype is "system" but it is optional parameter. Keylock is the name of FHEM device which represents the switch and tells the system if the doors are locked or unlocked. For example you can use for the switch the ELV FS20 TFK (use Eventmap to define in FHEM off as unlock and on as lock).
Example
define door_acess RFID system /dev/ttyUSB2 doorkey
define user1 RFID user 0005354301

Set
Nothting defined

Get
Nothing defined

Readings
lock/unlock for each user with time of last action

Attributes
active  (value 0 or 1)
if the value of attribute "active" is 0 then the user is not active and can not lock/unlock the door
restricted  (format:  <nameofday>-<beginning of restriction hh:mm:ss><end of restriction hh:mm:ss>-
Example of attribute "restricted"
Friday-00:00-07:00/Saturday-00:00-07:00
The user can not unlock/lock the door on Friday and Saturday from midnight to 7 o'clock in the morning

The reason to create FHEM module was because I constantly had a problem that someone in my family (specially kids) lost the keys. Because I already had some gadgets in place and also FHEM with CUL device I set up the following solution:
•   electric motor key lock (Conrad KM300) with remote interface (ELV KM300 RI). With remote interface you power and control the motor key lock (lock, unlock, open the door). Remote interface has simple UPS ELV USV12
•   FS20 1-Kanal-Universal-Empfänger UE1-2. The switch is connected to remote interface and enables to control motor key lock with FHEM
•   ELV FS20 TFK is a switch to indicate if doors are locked or unlocked. Use Eventmap to define off as unlock and on as lock.
•   RFID reader 125Khz EM4100 with USB 2.0 to UART TTL 6PIN Connector Module
•   FHEM server with CUL device
•   define in FHEM notify procedure in order to trigger the FS20 UE1-2 switch to unlock or lock the motor key lock

I hope this module will be useful for someone.

Lectere

Cool stuff!, looks really nice.

Been looking for a simelair may to unlock my door!

Really appricate your effort, and if you have some more time, I'd really like to see a how-to with screenshot and shared code. (in english)

Two questions;
-could a simelar system be used with NFC of your phone?
-It is not a bit unsafe to have your lock operated over FS20?, I mean, its not very hard to send a 'open' command on every possible house code...

Great post, very inspiring!
SMSPassword redundant two-factor authentication for Netscaler, Vmware View, Cisco, Juniper, etc via SMS

http://www.smspassword.com

andrejs

#2
Thank you for showing the interest for the solution. Unfortunately the script does not cover the RFID Readers for  NFC because such readers works on the frequency 13,56 mHZ and I think also the protocol is different. The RFID reader which is supported with this script works on frequency 125 KHz.
Yes you are right it is not safe but this is just temporary solution. I have in the near future the intention to replace FS20 1-Kanal-Universal-Empfänger UE1-2 with the similar one from Homematic Funk-Schaltaktor, 4-fach (is more safe) but for that reason I need to buy another CUL device.
After I finish my vacation I will post some photos.

Andrej
 

andrejs

#3
Finally I found time to create the scheme of door access control (see rfid_scheme.jpg) in my house in order explain more in details:

1.   RFID reader 125 kHz is connected through USB 2.0 to UART TTL 6pin to PC where the FHEM server is installed. Originally the RFID reader is in a black plastic box (see rfid_reader.jpg). I remove the black plastic box and on PCB of RFID reader solder 3 wires: VCC, GND, Data. These 3 wires are connected to USB 2.0. to UART TLL 6pin module: VCC to 5v, GND to GND and Data to TXD. In order to have nice box I bought RFID Door Access Control Reader Controller CK-138 (bought on Ebay) and use just the plastic box of this controller. First I drill the hole for led diode and then glue the PCB of RFID Reader in the box. I paid for all three components 17 EUR.
To read the number of the RDIF card/key the 99_RFID.pm file should be copied to FHEM directory and then you need define in fhem.cfg:
Subtype system you define just once   
define <some name> RFID system /dev/ttyUSBx <keylock – it is optional>
for each user you need to define separately
define <name of the user> RFID user <rfid card number 10 digits>

Everytime the card is put on RFID reader the FHEM system reads the card:
•   If the card (user) is defined then "lock" or "unlock" value is written
•   If the card (user) is not defined then  "unknown" value is written
•   If the card (user) is defined but attribute active is 1 then  "not_active " value is written
•   If the card (user) is defined but attribute restricted is defined and current time is in inside restricted day and time then "restricted" value is written

If you want to control any other device in FHEM then you shall define in FHEM NOTIFY procedure. In my case with notify procedure I trigger the FS20 UE1-2 switch to unlock or lock the motor key lock. I created in fhem.cfg the following notify procedures:
define door_lock NOTIFY keylock {if ( Value ("keylock") eq "lock") {fhem("set UE1_unlock on")}}
define door_unlock NOTIFY keylock {if ( Value ("keylock") eq "unlock") {fhem("set UE1_lock on")}}

2.   ELV Keymatic RI is controlled by two FS20 EU1-2 one is for lock (UE1_lock ) and the second (UE1_unlock ) is for unlock.
3.   The electric motor lock KM300 (it can be also ABUS CFA 1000) is connected with special cable (I got the cable in the package with ELV Keymatic RI) to ELV Keymatic RI.
4.   FS20 TFK is defined in FHEM as "keylock" and it is connected to micro switch to indicate if doors are locked or unlocked. The micro switch should be placed near the hole of strike plate where bolt of mortise lock entered.
5.   From  UPS ELV USV12  the ELV Keymatic RI is powered. In the UPS ELV USV12 are recharcheable batteries powered by AC DC Adaptor.

I checked on internet but unfortunately I found out that ELV Keymatic RI is not available anymore so my solution is outdated. Maybe the solution can be to use RFID reader 125Khz EM4100 with USB 2.0 to UART TTL 6PIN Connector Module and for unlock/lock the door with Keymatic KM300 Motorlock and HomeMatic LAN Konfigurations-Adapter -  for details see  http://forum.fhem.de/index.php/topic,11715.0.html

Lectere

Cool, good stuff! thanks for sharing!

I'm gonna for the wired NFC version, if I can build it!
SMSPassword redundant two-factor authentication for Netscaler, Vmware View, Cisco, Juniper, etc via SMS

http://www.smspassword.com

andrejs

Thanks. I am also interested for NFC solution. Please share it to me when it will be ready. 

andrej

Lectere

#6
Well... :) I've got to get the NFC reader first.

Since I'm running on a Raspi, first step is to find a compatible USB device for libnfc;

https://code.google.com/p/libnfc/

Think this is the list;

http://nfc-tools.org/index.php?title=Devices_compatibility_matrix


First goal is to turn on a light with my phone. If that works, I can try a lock... :)
SMSPassword redundant two-factor authentication for Netscaler, Vmware View, Cisco, Juniper, etc via SMS

http://www.smspassword.com

Lectere

I think this is the best option;

acr122 usb

You can get it around 40 euro in europe. Accourding to this; http://nfc-tools.org/index.php?title=Devices_compatibility_matrix it's compatible as 'initiator'. But since we only need to verify a phone NFC, for access, that should be enough.
SMSPassword redundant two-factor authentication for Netscaler, Vmware View, Cisco, Juniper, etc via SMS

http://www.smspassword.com

breezybadger

Hey, did you see any chance to use the HID ( my RFID is reconiced as Keyboard ) to use as input device ? What device should i used to add this to my FHEM config (/dev/input...? ) ?

eppi

Hi andrejs
Thank you very much for the module! I have a question: I am planning to use two TTL-USB for RFID, one for the front door and one for the garage door.
Therefore it is necessary that the RFID reader knows the Location and opens the corresponding device.

Is that possible?

Many thanks!
Greets Dani

no_Legend

Hi Eppi,

it looks that there should not be a problem.
You can give each reader a unique name.

But i Think can be a problem.
If you use the same reader at one system, it can happen that the reader is change the unix device name.
So it will be better to use udev if the reader got a unique serial.
IntelNUC mit Ubuntu mit FHEM immer aktuell,2x HMLAN, CUL443, CUL868 -homekit/siri -tablet ui -homebridge
Device, diverse:
HM-SEC-KEY,HM-LC-BL1-FM,HM-SEC-SD,HM-Sen-DB-PCB,HM-Sec-RHS,HM-Sec-SC-2,HM-WDS10-TH-O,Harmony,Netamo, 433MHz Steckdosen uvm.

eppi

Hi together
I have problems and need your support.
I installed the USB-TTL Adapter without problem

My Define:
list door_access
Internals:
    DEF system / dev/ttyUSB0
    DEVICE NAME / dev/ttyUSB0
    FD 10
    KEYLOCK
    NAME door_acess
    NR 105
    PARTIAL
    STATE opened
    SUBTYPE system
    TYPE RFID
Attributes:
    room RFID

   
The system shows me "opened", so far so good!

I created the User:

list user1:
Internals:
    CARDNR 0006994919
    DEF user 0006994919
    NAME user1
    NR 106
    STATE?
    SUBTYPE user
    TYPE RFID
Attributes:
    room RFID


If I go with the card over the RFID-Reader, it reacts by a beep, but the event monitor in FHEM ist empty.
Can you help me?

Btw: Sorry for my bad english...

andrejs

Hi eppi. First I would like to ask you which RFID reader do you use? If "RFID reader 125Khz EM4100" is not used then the module 99_RFID.pm does not work correctly.


eppi

Hi Andrejs
i use the RDM630 http://coldtears.lin3.siteonlinetest.com/files/RDM630-Spec..pdf

I have a python script found, which I have adapted so does the RDM 630 with the USB TTL UART (see attachment).

Your modules I can not load as before. Do you have any idea what I'm doing wrong?
Thank you very much!

Greets Dani

andrejs

Dear Dani,

as I said fhem module 99_RFID.pm is written just for RFID reader 125Khz EM4100 and  other readers will not work correctly because the output format of data is different. So the 99_RFID.pm module should be changed in order to get card number from RDM630 and also in define sentance we should add the model (for example EM4100, RDM630) in order to support different output format of data. Unfortunately I am not able to test  because I do not have RDM630 in place. I propose for the start that you make change in 99_RFID.pm line -  please just delete hash sign (#) before the following line:
#Log 3, "$mybufdec + $RFID_count";
With this change the output data from your RFID reader will be written in log file of FHEM. I would like to ask you to go with the card over your RFID reader and send to me the FHEM log file in order to see what kind of output data came from RFID reader RDM630.

Regards

Andrej