Hauptmenü

RFID Module

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

Vorheriges Thema - Nächstes Thema

andrejs

#90
Daniel,
the protocol to convert in decimal ID Tag is very strange. I found the solution here https://maniacbug.wordpress.com/2011/10/09/125khz-rfid-module-rdm630/. In attached file you will find the amended fhem module 99_RFID.pm where I added new model of reader RDM630A (use this!). I summarize all instructions of RFID module below.
You should define devices:
define RFIDIO RFID system /dev/ttyAMA0@9600 RDM630A
define daniel RFID user 0009953857 ALL
attr daniel rfid_active 1

I hope it will work!

Andrej

***************************************************************************************************************
Define
Define <name> RFID  <subtype> <devicename> <model> <card number> <authorisation> <keylock> <doorstate>

<subtype> can be "user" or "system"
<devicename> specifies the serial port@baudrate or IP address with port number 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/ttyUSBX device will be created.
<card number> should be defined if subtype is "user". Card number is at least 10 digit number which is normally printed on RFID key or card.
<model> 3 models are possible to define:
EM4100 - http://www.ebay.com/itm/USB-RFID-Contactless-Proximity-Smart-Card-Reader-125Khz-EM4100-Windows-arduino-/111114333563 (for connection do not use USB port on the USB Reader but open the plastic box of the reader and connect wires on the pins on PCB. For the connection from pins on PCB to the USB of the computer use the USB 2.0 to UART TTL 6PIN Connector Module)
RDM630 - http://www.seeedstudio.com/depot/datasheet/RDM630-Spec..pdf
RDM630A - http://www.ebay.de/itm/331221365816?_trksid=p2060353.m2749.l2649&ssPageName=STRK%3AMEBIDX%3AIT

<authorisation> should be defined if subtype is "user". Parameter specifies for which RFID reader or readers is user authorised. Possible values:
ALL - user has access/authorisation to all RFID readers
NONE - user has no access/authorisation to RFID readers
PART(reader1,reader2,...)  - user has access/authorisation to RFID readers defined in brackets seperated by comma
<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 or HomeMatic 3-Kanal-Funk-Schließerkontakt-Interface (for ELV FS20 use Eventmap to define in FHEM off as unlock and on as lock).
<doorstate> should be defined if subtype is "system" but it is optional parameter. Doorstate is the name of FHEM device which represents the switch and tells the system if the doors are opened or closed. For example you can use for the switch the ELV FS20 TFK or HomeMatic 3-Kanal-Funk-Schließerkontakt-Interface (for ELV FS20 use Eventmap to define in FHEM off as open and on as closed).
Example
define door_acess RFID system /dev/ttyUSB2@9600 EM4100 doorkey doorswitch
define door_acess RFID system 192.168.1.101:3000 RDM630 doorkey doorswitch
define user1 RFID user 0005354301 PART(door_acess)

Set
Nothting defined

Get
Nothing defined

Readings - for each user with time of last action
lock/unlock
no_auth
no_value
not_active
restricted
door_notclosed
not_correct
unknown cardnr

Attributes (define all attributes in fhem cfg file using "attr global userattr rfid_active")
rfid_active  (value 0 or 1)
if the value of attribute "rfid_active" is 0 then the user is not active and can not lock/unlock the door. If the attribute is not defined then the default value is 0.
rfid_restricted  (format:  <nameofday>-<beginning of restriction hh:mm:ss><end of restriction hh:mm:ss>-
If there is no restrictions for the user then the value of attribute should be 0.
Example of attribute "rfid_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

breezybadger

#91
Hi, its a little bit to early for a I Love You. Thanks again for your support, but it still doesn't work.  Here Again the Logfile
2015.05.13 13:18:12 5: 2 + 0 +
2015.05.13 13:18:12 5: 55 + 1 +
2015.05.13 13:18:12 5: 52 + 2 +
2015.05.13 13:18:12 5: 48 + 3 + 48
2015.05.13 13:18:12 5: 48 + 4 + 4848
2015.05.13 13:18:12 5: 57 + 5 + 484857
2015.05.13 13:18:12 5: 55 + 6 + 48485755
2015.05.13 13:18:12 5: 69 + 7 + 4848575569
2015.05.13 13:18:12 5: 50 + 8 + 484857556950
2015.05.13 13:18:12 5: 52 + 9 + 48485755695052
2015.05.13 13:18:12 5: 49 + 10 + 4848575569505249
2015.05.13 13:18:12 5: 52 + 11 + 4848575569505249
2015.05.13 13:18:12 5: 48 + 12 + 4848575569505249
2015.05.13 13:18:12 5: 3 + 13 + 4848575569505249
2015.05.13 13:18:12 5: fname: RFIDIO cnr_attr:  cnr_reader: 5208508993404686921 status: closed action: unknown 5208508993404686921

andrejs

Sorry Daniel I missed something - it was late night. I corrected my mistake and now it should be OK.

Andrej

breezybadger

I have no Idea how you did this, but it works! Thanks so much for your support!

andrejs

Daniel it was pleasure to help you. It is funny that the reader wihich is declared as RDM630 has totally different protocol to convert raw data from RFID reader to ID Tag but at the end I need to amend the script. In your case I was lucky beacuse the example is available on the web. Have fun!

Andrej

breezybadger

Sorry to bother you again, It seems I don't get the concept of your work. The reading now works, every time I slide the Tag over the Reader it says in the Eventmonitor RFID RFIDIO 0009953857: lock/unlock

Fine so far, but I want to use my Tags to disarm my Alarmsystem. So I created a dummy "alarm_status". This dummy switched to "on" by hitting a remote button, how do I manage to set this dummy to "off" when slipping a Tag over the reader?

I was assuming your script changes the value of a variable from "lock" to "unlock" or "close" to "open" ...

excuse my stupid questions
Daniel

andrejs

Daniel, there is no stupid questions. Let me explain in short how the script works. In the case the parameter <keylock> is not defined for the device RFIDIO the reading state "lock/unlock" is defined because the system does not know what to do. if the keylock device (in may case it is the name of HM switch defined in FHEM which has "closed" and "open" state) is defined then the script will check the state of device keylock:
- if state of device keylock is "open" the result of the slide of the tag over the reader will be the change of the reading state of device in your case daniel and also RFDIO to "lock"
- if state of device keylock is "closed" the result of the slide of the tag over the reader will be the change of the reading state of device in your case daniel and also RFDIO to "unlock"
These states are hardcode in the script and this can be changed but I will need to amend the script and add some new attributes.

If you will need the rfid reader just to arm and disarm the alarm system and dummy alarm_status will be always correct (also when you will arm and disarm alarm system manually on the keyboard)  then you should just create DOIF:
define alarmoff DOIF ([RFIDIO] eq "lock/unlock" and  [alarm_status] eq "on") (set alarm_status off)
define alarmon DOIF ([RFIDIO] eq "lock/unlock" and  [alarm_status] eq "off") (set alarm_status on)
 
Andrej

breezybadger

And thanks again, for your explanation.

Its seems I understood the concept but still miss a point. I tried some different defintions:

define alarm_status dummy
#attr alarm_status eventMap on:lock off:unlock
define alarmoff DOIF ([RFIDIO] eq "lock/unlock" and  [alarm_status] eq "on") (set alarm_status off)
define alarmon DOIF ([RFIDIO] eq "lock/unlock" and  [alarm_status] eq "off") (set alarm_status on)
define RFIDIO RFID system /dev/ttyAMA0@9600 RDM630A
define daniel RFID user 0009953857 ALL
attr daniel rfid_active 1


Leads to a one time change, but after the first slide no changes are applied anymore.

My second attempt was:
define alarm_status dummy
attr alarm_status eventMap on:lock off:unlock
#define alarmoff DOIF ([RFIDIO] eq "lock/unlock" and  [alarm_status] eq "on") (set alarm_status off)
#define alarmon DOIF ([RFIDIO] eq "lock/unlock" and  [alarm_status] eq "off") (set alarm_status on)

define RFIDIO RFID system /dev/ttyAMA0@9600 RDM630A alarm_status
define daniel RFID user 0009953857 ALL
attr daniel rfid_active 1


This leads to the a "not_correct" messages in the Event Monitor.

My alarm System changes alarm_status to "on" , by slipping a valid tag it should get the status "off"

Thanks again.


andrejs

#98
Daniel,

in the first definition you should add to DOIF the attribute if you want to have more then on time change
attr alarmoff do always
attr alarmon do always

The second definition the reading state "not_correct" derived from the fact that the reading state of "keylock" should be "open" or "closed". According to this just set value (open or closed) of dummy and there is no need to set attribute:   
define alarm_status dummy
set alarm_status open or set alarm_status closed
define RFIDIO RFID system /dev/ttyAMA0@9600 RDM630A alarm_status
define daniel RFID user 0009953857 ALL
attr daniel rfid_active 1

Andrej

breezybadger

I could not thank you more!!! Now I got a awesome alarm system which can only be disarmed by using your Script! Awesome work, you may work a little bit on it to make it more flexible ( make your open closed status definable ) and than you should check it in the trunk!

Thanks!

andrejs

Good news. I agree the script it is "hardcoded". I will amend the module and add attributes to make this more flexible. Thanks again for your time.

Andrej

andrejs

#101
I managed to change the script in order to be more flexible:
- all 11 reading states can be changed using attribute eventMap in RFID system
- the default state of <keylock>/<doorstate> device can be changed using attribute rfid_skeylock/rfid_sdoorstate. Examples are in the instructions bellow.

How can I do (or find the instructions) this:
Zitatand than you should check it in the trunk!

Andrej
****************************************************************************************************************** 
Define
Define <name> RFID  <subtype> <devicename> <model> <card number> <authorisation> <keylock> <doorstate>

<subtype> can be "user" or "system"
<devicename> specifies the serial port@baudrate or IP address with port number 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/ttyUSBX device will be created.
<card number> should be defined if subtype is "user". Card number is at least 10 digit number which is normally printed on RFID key or card.
<model> 3 models are possible to define:
EM4100 - http://www.ebay.com/itm/USB-RFID-Contactless-Proximity-Smart-Card-Reader-125Khz-EM4100-Windows-arduino-/111114333563 (for connection do not use USB port of the USB Reader but open the plastic box and find the connections for serial data stream. For details see: http://www.pcmx.de/?p=216. In order to connect reader to the computer of FHEM server I use the USB 2.0 to UART TTL 6PIN Connector Module.
RDM630 - http://www.seeedstudio.com/depot/datasheet/RDM630-Spec..pdf
RDM630A - http://www.ebay.de/itm/331221365816?_trksid=p2060353.m2749.l2649&ssPageName=STRK%3AMEBIDX%3AIT

<authorisation> should be defined if subtype is "user". Parameter specifies for which RFID reader or readers is user authorised. Possible values:
ALL - user has access/authorisation to all RFID readers
NONE - user has no access/authorisation to RFID readers
PART(reader1,reader2,...)  - user has access/authorisation to RFID readers defined in brackets seperated by comma
<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 or HomeMatic 3-Kanal-Funk-Schließerkontakt-Interface (for ELV FS20 use Eventmap to define in FHEM off as unlock and on as lock).
<doorstate> should be defined if subtype is "system" but it is optional parameter. Doorstate is the name of FHEM device which represents the switch and tells the system if the doors are opened or closed. For example you can use for the switch the ELV FS20 TFK or HomeMatic 3-Kanal-Funk-Schließerkontakt-Interface (for ELV FS20 use Eventmap to define in FHEM off as open and on as closed).
Example
define door_acess RFID system /dev/ttyUSB2@9600 EM4100 doorkey doorswitch
define door_acess RFID system 192.168.1.101:3000 RDM630 doorkey doorswitch
define user1 RFID user 0005354301 PART(door_acess)

Set
Nothting defined

Get
Nothing defined

Readings - for each user with time of last action
lock/unlock
lock
unlock
no_auth
no_value
NAV_keylock
NAV_door
restricted
door_notclosed
not_correct
unknown cardnr

Names of all readings can be changed using attribute eventMap for RFID system:
attr  RFIDIO eventMap lock/unlock:open/close lock:close unlock:open

Attributes
rfid_active  (value 0 or 1)
if the value of attribute "rfid_active" is 0 then the user is not active and can not lock/unlock the door. If the attribute is not defined then the default value is 0.
rfid_restricted  (format:  <nameofday>-<beginning of restriction hh:mm:ss>-<end of restriction hh:mm:ss>
If there is no restrictions for the user then the value of attribute should be 0.
Example of attribute "rfid_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
rfid_skeylock
if the parameter <keylock> is defined (see instruction above) the default state of the "keylock" device should be "open" or "closed". If the "keylock" states are different this can be changed using attribute rfid_skeylock: attr RFIDIO rfid_skeylock  open:on closed:off 
rfid_sdoorstate
if the parameter <doorstate> is defined (see instruction above) the default state of the "doorstate" device should be "open" or "closed". If the "doorstate" states are different this can be changed using attribute rfid_sdoorstate: attr RFIDIO rfid_sdoorstate  open:on closed:off 

breezybadger

Dear Andrejs,


I kind of break my config , I hope you may help.

RFID daniel 0009953857: not_correct <- What does it mean? The Tag No is definitely the right no, the user is active and has restriction 0

Kind Regards
Daniel

andrejs

Daniel which version of RFID module are you using? Is this one "# $Id: 99_RFID.pm 1098 2015-06-11 23:30:08Z andrejs $" (see at the beggining of 99_RFID.pm script) ?

heikoxxxx

#104
Hello Andre,

first of all, thanks for that great FHEM module. It works fine for me for some time. Using that module to get access for my home, Module is connected with ESPEASY Serial Server.

But some time ago i changed one key from 0000347048 to 0083515152 and after that i get often problems with FHEM, but dont know where they come from.

After a long time and long term tests i have seen, that the Raspi RAM got nearly to 60-70% and CPU 40-60% (also some time after saving) so i get often that error:

2019.07.01 00:00:12 1: Cannot fork: Cannot allocate memory
2019.07.01 00:00:12 1: Cannot fork: Cannot allocate memory
2019.07.01 00:00:12 1: in CANNOT_FORK
2019.07.01 00:00:14 1: Cannot fork: Cannot allocate memory
2019.07.01 00:00:14 1: Cannot fork: Cannot allocate memory
2019.07.01 00:00:14 1: in CANNOT_FORK


Fhem also often hangs up or was very slow.

So i looked in the log file what was changed before this error occured the first time and see, that the only thing what i did is changing the RFID Chip Number.
I updated to laterst Version  from 2015-06-11 and tried with RDM630A and RDM630 but allways the same issue.

Than i changed my RFID Number to the old one again and selected RDM630 and everything was working fine for me. RAM is constand on 5 to 15% and CPU 10 to 20%

Do you think problem is the bigger number of that new chip? Do you have any Idea to fix that issue?


Thanks a lot