deconz-rest-plugin icon indicating copy to clipboard operation
deconz-rest-plugin copied to clipboard

ADD code/RFID support to keypad device.

Open Smanar opened this issue 2 years ago • 25 comments

This code WIP permit.

  • Add more code than the master one, using PUT /api/<apikey>/alarmsystems/<id>/config/code with {index,"code"}
  • Remove code using DELETE /api/<apikey>/alarmsystems/<id>/config/code with {index,"code"} (can use master code too if forget the code)
  • Memorise code or RFID using PUT /api/<apikey>/alarmsystems/<id>/learncode/<index>

You can for exemple use PUT /api/<apikey>/alarmsystems/<id>/learncode/1 Put your RFID card on the keypad, and the RFID will be memorised on index 1.

Code is not finished (can't make the timer working) and it's more a proof of concept, not sure for my request choice.

See https://github.com/dresden-elektronik/deconz-rest-plugin/issues/5352

Smanar avatar Mar 29 '22 16:03 Smanar

Hello any idea where the PR will be in a stable version ?

Idaho947 avatar Jun 29 '22 15:06 Idaho947

Good question ^^. For the moment this part is more a proof of concept, but IDK if @manup wana use it or not ?

IDK where you are ATM on your device integration, have answered you on discord to know what is your third app, you can use your keypad without this PR, this one just add more features.

Smanar avatar Jun 29 '22 17:06 Smanar

Have tried something to make 60s timer when entering in learnmode, if someone can test the new code ?

  • Compile the actual code (it was just updated)
  • Enable deconz log with flag "info"
  • Enter learn mode PUT /api/<apikey>/alarmsystems/<id>/learncode/1
  • Put your RFID card on the keypad
  • Look at logs

If you can try in less than 60s, then more than 60s ?

Smanar avatar Jul 06 '22 15:07 Smanar

Hey good news but how can I test it ? I've juste a production environnement.

Idaho947 avatar Jul 06 '22 16:07 Idaho947

On jeedom it's possible. You have the procedure here https://github.com/dresden-elektronik/deconz-rest-plugin/wiki/Compiling-the-REST-plugin-for-device-specific-testing So for you, after having installed deconz :

sudo apt install deconz-dev
git clone --branch keypad_rfid https://github.com/Smanar/deconz-rest-plugin.git
cd deconz-rest-plugin
qmake && make -j2
sudo cp ../libde_rest_plugin.so /usr/share/deCONZ/plugins

Warning the last step replace the lib file libde_rest_plugin.so, so to prevent problem better to make a backup of this file, on another folder (rename it don't work, you relay need to move it) The procedure will close deconz, so you will need to restart the demon.

If you have a production environnement and a production environnement, no danger.

The first compilation take lot of time.

Here the code I want to test

  //Check timer
        if (deCONZ::TimeSeconds{60} < (deCONZ::steadyTimeRef() - alarmSys->learnTimer))
        {
            alarmSys->learnModeIndex = 0;
            DBG_Printf(DBG_IAS, "[IAS ACE] Timer exceed to set new code\n");
        }
        else
        {
            //memorise it
            if (alarmSys->setCode(alarmSys->learnModeIndex, pinCode))
            {
                DBG_Printf(DBG_IAS, "[IAS ACE] code added\n");
            }
            else
            {
                DBG_Printf(DBG_IAS, "[IAS ACE] adding code failed\n");
            }

so you will have log message for all situations

Smanar avatar Jul 06 '22 17:07 Smanar

Ok but my deconz server is not in the jeedoms VM. Maybe I'll try to instal the dev version of deconz on a new VM, import my backup on it and test it.

Idaho947 avatar Jul 06 '22 17:07 Idaho947

Hello, I too only have a production environment. I backed up libde_rest_plugin.so file. I guess I only have to replace the new one by the one I backed up to perform a full rollback? (I had to install qtcreator & qt5-default packages as an additional step to have the qmake command working.)

I tried to activate the learn mode with curl -H "Content-Type: application/json" -X PUT http://aaa.bbb.ccc.ddd:pppp/api/APIKEY/alarmsystems/1/learncode/1

but in either case, I got nothing in the logs (whether I wait for the 60s to expire or if I scan a rfid tag)... I don't know what I am doing wrong here.

Gw3n4 avatar Jul 10 '22 13:07 Gw3n4

Update: I still get nothing in the info logs, so I must be doing something wrong but:

  • when I activate the learn mode and scan the rfid tag on the keypad, wait for a while and then test if the rfid tag can arm/disarm the alarm it did not work
  • when I activate the learn mode and scan the rfid tag on the keypad and then press the disarm key, wait for a while and then test if the rfid tag can arm/disarm the alarm, it does work

I recall having read that the keypad sends the RFID code only if arm_away/arm_stay/arm_night/disarm key is pressed.

I managed to learn a 2nd RFID tag with curl -H "Content-Type: application/json" -X PUT http://aaa.bbb.ccc.ddd:pppp/api/APIKEY/alarmsystems/1/learncode/2

I tested the deletion, however it seems to only work with the master code0.

After having deleted the 2 tags, I tested adding the RFID tags without the learn process with

  • curl -H "Content-Type: application/json" -X PUT -d "{"1": "+UID"}" http://aaa.bbb.ccc.ddd:pppp/api/APIKEY/alarmsystems/1/config/code and it only worked when I added the + before the actual UID. Again the deletion only works with the master code0.

Gw3n4 avatar Jul 10 '22 13:07 Gw3n4

I guess I only have to replace the new one by the one I backed up to perform a full rollback?

Yep exactly, and the "new one" is installed during the procedure, the last action is a file copy

And yes, you need to press "disarm" or "arm" button after showing a tag or use a new pin code to memorise it, you can do both if you want, show a RFID + use 4 pin number than press "arm" or "disarm", the action will be by-passed but the code or rfid will be memorised instead.

Where are you reading the UID ? And yes ^^, all code in RFID start by a "+" https://github.com/dresden-elektronik/deconz-rest-plugin/issues/5352#issuecomment-1026091216

So need to use it too for the delete request. The delete feature was tested for code only, not RFID , because the previous user haven't acess to the UID.

Smanar avatar Jul 11 '22 15:07 Smanar

Hello, I read the UID with my smartphone.

I tested again the code deletion, not with an RFID tag this time but a 4 digit code (on index 3) --> Still the same, the deletion only works with the master code0 on my side...

Gw3n4 avatar Jul 11 '22 17:07 Gw3n4

Ha yes I remember the last user have a Iphone so harder to find application.

BTW I don't find the problem for the deletion issue, can you show the API answer when you make the request ? And you have a log during the code check visible with the flag "info"

DBG_Printf(DBG_INFO, "test %s\n",sec.uniqueId);

I m seing an issue where no code can be deleted at all (I m re-wrting the code instead of an empty value), but if it work with code 0 ....

Smanar avatar Jul 12 '22 16:07 Smanar

OK I think I managed to find the logs.

Here is what I get when I create code 3 : 21:13:06:727 HTTP API PUT /api/APIKEY/alarmsystems/1/config/code - aaa.bbb.ccc.ddd 21:13:06:727 Text Data: {"3": "1234"} 21:13:06:727 ApiMode: 0 21:13:07:088 Update code succesfull, index 3 21:13:07:088 [{"success":{"/alarmsystems/1/config/configured":true}}]

when I delete with code3 : 21:13:46:269 HTTP API DELETE /api/APIKEY/alarmsystems/1/config/code - aaa.bbb.ccc.ddd 21:13:46:269 Text Data: {"3": "1234"} 21:13:46:269 ApiMode: 0 21:13:46:631 test ???~ 21:13:46:958 test ???~ 21:13:47:284 test ???~ 21:13:47:991 Update code succesfull, index 3

when I delete with code0 21:14:47:994 HTTP API DELETE /api/APIKEY/alarmsystems/1/config/code - aaa.bbb.ccc.ddd 21:14:47:994 Text Data: {"3": "code0"} 21:14:47:994 ApiMode: 0 21:14:48:763 Update code succesfull, index 3

but still the same behaviour : I can still arm/disarm the alarm with code3 after the first 2 steps, not after the third one with code0. I agree with you, as long as it works with code0, this is no priority at all :)

Gw3n4 avatar Jul 12 '22 19:07 Gw3n4

So now that I found the logs, here is what I get when testing the learn mode:

21:39:17:190 HTTP API PUT /api/APIKEY/alarmsystems/1/learncode/3 - aaa.bbb.ccc.ddd 21:39:17:190 ApiMode: 0 21:39:17:190 Enable learn mode for code ... <RFID tag presented and disarm key pressed> ... 21:39:22:957 Update code succesfull, index 3

I get the same first 3 lines but no other info when waiting for the 60s timer to expire.

Gw3n4 avatar Jul 12 '22 19:07 Gw3n4

Ok so was the issue I have see. In fact I never delete the code, but use the same used in the request, so it do nothing or replace it by the code0 ^^.

Have pushed a better version

cd deconz-rest-plugin
git pull
qmake && make -j2
sudo cp ../libde_rest_plugin.so /usr/share/deCONZ/plugins

The compilation will be faster this time.

And for the lasts tests, logs are visible on flag "IAS" And by curisoity what is "- aaa.bbb.ccc.ddd" on your log ?

Smanar avatar Jul 13 '22 16:07 Smanar

Someone can confirme me

  • The RFID tag can workk if using the "arm" or 'disarm" key after showing the tag.
  • The delete request work with last code ?

Else I will change the PR status to Draft.

Smanar avatar Jul 19 '22 15:07 Smanar

Sorry I can't. I think my rfid tag are lost by the postman...

Idaho947 avatar Jul 19 '22 16:07 Idaho947

Hi, I configured one RFID tag with learnmode --> OK, can arm/disarm with the tag I configured one RFID tag by adding the UID with the REST API --> OK, can arm/disarm with the tag I configured a 3rd code with the REST API then deleted with the configured code --> OK code can arm/disarm when I add it, and cannot anymore when deleted (without having to use the master code0 now ;) )

Thanks Smanar for the evolution :)

Gw3n4 avatar Jul 19 '22 21:07 Gw3n4

Ok nice, thx, so I let the PR as it, ready for review.

You need to use the constructor RFID ? if you use a basic one It dont work ?

Smanar avatar Jul 20 '22 15:07 Smanar

Hi, The rfid tags I use have nothing to do with frient. So I guess any tag would do.

Gw3n4 avatar Jul 23 '22 08:07 Gw3n4

I finally test it and work very well with my rfid tag bought on amazon.

Idaho947 avatar Aug 13 '22 19:08 Idaho947

Any update on this? Is it going to be merged?

Blakko avatar Oct 13 '22 16:10 Blakko

I finally test it and work very well with my rfid tag bought on amazon.

Which one please ?

BabaIsYou avatar Jan 08 '23 13:01 BabaIsYou

Those : https://www.amazon.fr/gp/product/B07YN6GX1F/ref=ppx_yo_dt_b_search_asin_title?ie=UTF8&psc=1

Idaho947 avatar Jan 08 '23 13:01 Idaho947

Thanks !

BabaIsYou avatar Jan 08 '23 18:01 BabaIsYou

Hello any news about the rfid intégration ?

Idaho947 avatar Mar 26 '23 13:03 Idaho947