One button code lock

Moderators: grovkillen, Stuntteam, TD-er

Message
Author
Dick60
Normal user
Posts: 243
Joined: 11 Feb 2018, 17:35
Location: The Netherlands

One button code lock

#1 Post by Dick60 » 20 Jun 2023, 11:30

Can someone help me get started with a single button code (un)lock. It must activate a relay.

TD-er
Core team member
Posts: 8756
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: One button code lock

#2 Post by TD-er » 20 Jun 2023, 12:07

I think you have to be a bit more specific...

What are you thinking of?
One of those 1-Wire i-button key chains?
Or pressing a specific sequence using a normal button?

Dick60
Normal user
Posts: 243
Joined: 11 Feb 2018, 17:35
Location: The Netherlands

Re: One button code lock

#3 Post by Dick60 » 20 Jun 2023, 12:24

Ahh, I am searching for a one button (un)lock after finishing a button- push sequence. It it is the wrong sequence, the relay must be blocked for a some time. If is as an add-on for my current door openen (extra safety). As you mentioned, a 1 wire solution is also a possibility but I don't know how that works.

TD-er
Core team member
Posts: 8756
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: One button code lock

#4 Post by TD-er » 20 Jun 2023, 13:58

Thos w-Wire buttons are like a key chain with something at the end which looks a lot like a coin cell battery.
You can press those against some contacts and then it will transmit a specific ID.

The protocol on the wire is like those 18b20 temperature sensors.

A button push sequence may be a bit tricky to implement as it is quite hard to not make it frustrating to use.

Problem with mechanical switches (especially when used with longer cables) is that they don't make a firm single contact.
They often "bounce" a bit.

So you need to implement some filtering (either in software or via some capacitor, or both) to reject short bounce signals.
However when requiring a tapping sequence you probably need quite a short pulse, but also not accept noise.
That makes it hard to make it right.

The switch plugin can be configured to output different events for short and long pulses.
However when making a long pulse, you also get the event for a short pulse.
This makes capturing a specific sequence of long and short pulses rather complex.
See also:
https://espeasy.readthedocs.io/en/lates ... management
https://espeasy.readthedocs.io/en/lates ... management

You could make something like 4 short pulses and 1 large pulse like this:

Code: Select all

on switch#state do
  if %eventvalue1%=1
    let,1,[int#1]+1 // Count pulses
    timerset,1,1 // Set timer to clear the counter    
  else if %eventvalue1%=11 and [int#1]=3
    // Accept the code
    let,1,0 // Clear counter
    
    // Do stuff like switching a relay to open a door, etc.
    // for example: longpulse,N,1,<duration>
    // See: https://espeasy.readthedocs.io/en/latest/Plugin/P000_Relay.html?highlight=longpulse#commands   
  
  endif
endon

on rules#timer=1 do
  let,1,0 // Clear counter
endon

Dick60
Normal user
Posts: 243
Joined: 11 Feb 2018, 17:35
Location: The Netherlands

Re: One button code lock

#5 Post by Dick60 » 20 Jun 2023, 14:14

Thos w-wire is New for me button in Google I cant't find anything. The other solution is alsof possible because rhe wires are short button behoren implementing something I want to read more abortus the w-wire switch. Do you have a link?

User avatar
Ath
Normal user
Posts: 3519
Joined: 10 Jun 2018, 12:06
Location: NL

Re: One button code lock

#6 Post by Ath » 20 Jun 2023, 14:29

Dick60 wrote: 20 Jun 2023, 14:14 Thos w-wire is New for me button in Google I cant't find anything.
That's a typo, should be 1-wire: https://www.google.com/search?q=dallas+1-wire+button
/Ton (PayPal.me)

Dick60
Normal user
Posts: 243
Joined: 11 Feb 2018, 17:35
Location: The Netherlands

Re: One button code lock

#7 Post by Dick60 » 20 Jun 2023, 20:21

Is the security of the button comparable to the rfid dongle? You hear more and more that rfid drops are easy to crack by a code generator, holding near the reader. Is that also the case with the 1 wire option?

TD-er
Core team member
Posts: 8756
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: One button code lock

#8 Post by TD-er » 20 Jun 2023, 21:33

You have to have electrical access to the button.
It isn't RF.

That doesn't mean it is truly safe.

The ESPEasy plugin for these only reads the unique serial number, which is relatively easy to clone.
The button itself does allow for some extra memory and if I'm not mistaken also some other security features like password protected memory. But that's not implemented in ESPEasy.

Maybe the best protection of those is that they are fairly unknown :)

User avatar
Ath
Normal user
Posts: 3519
Joined: 10 Jun 2018, 12:06
Location: NL

Re: One button code lock

#9 Post by Ath » 20 Jun 2023, 21:50

TD-er wrote: 20 Jun 2023, 21:33 Maybe the best protection of those is that they are fairly unknown :)
Hmm, security by obscurity :? :lol:
/Ton (PayPal.me)

TD-er
Core team member
Posts: 8756
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: One button code lock

#10 Post by TD-er » 20 Jun 2023, 21:52

Ath wrote: 20 Jun 2023, 21:50
TD-er wrote: 20 Jun 2023, 21:33 Maybe the best protection of those is that they are fairly unknown :)
Hmm, security by obscurity :? :lol:
More like security by obsolescence

Dick60
Normal user
Posts: 243
Joined: 11 Feb 2018, 17:35
Location: The Netherlands

Re: One button code lock

#11 Post by Dick60 » 20 Jun 2023, 22:23

Thanks guys, I know if someone wants to do bad things, no security system will stop that. I will order a 1 wire button for testen purpose and deside later what to implement and how. I also test the phisical button solution and test the debounching problemen. Enough for New experiences :D

TD-er
Core team member
Posts: 8756
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: One button code lock

#12 Post by TD-er » 20 Jun 2023, 23:21

Maybe order a few of them, so you can also test to reject another key.

Dick60
Normal user
Posts: 243
Joined: 11 Feb 2018, 17:35
Location: The Netherlands

Re: One button code lock

#13 Post by Dick60 » 05 Jul 2023, 18:08

I received my 1 wire reader and buttons. Installed the latest firmware on my esp8266 and connected the data line of the reader to GPIO 12 and the other wire to gnd. Also added a 4.7k pull-up resister to the 3.3v of the esp. A port number is generated (01-a3-be-8c-01-00-00-b5 [DS1990A]). Now the problem, I push one of the buttons to the reader and nothing happens, log log, nothing. I did not load the i buttons with a serial but assume that something is loaded already. non of the 7 ibuttons show the same result. Any idea what went wrong?

TD-er
Core team member
Posts: 8756
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: One button code lock

#14 Post by TD-er » 05 Jul 2023, 18:15

Also no event is generated?

Dick60
Normal user
Posts: 243
Joined: 11 Feb 2018, 17:35
Location: The Netherlands

Re: One button code lock

#15 Post by Dick60 » 05 Jul 2023, 18:25

no event was generated and forgot to mention that I selected the 1 wire Dalles sensor from the dropdown

TD-er
Core team member
Posts: 8756
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: One button code lock

#16 Post by TD-er » 05 Jul 2023, 19:54

Which plugin exactly?
It isn't the temperature sensor plugin.
It should be the "Switch input - iButton" (plugin P080)
This one should be available in "Collection A" builds.

Dick60
Normal user
Posts: 243
Joined: 11 Feb 2018, 17:35
Location: The Netherlands

Re: One button code lock

#17 Post by Dick60 » 05 Jul 2023, 19:57

I selected the Environment - 1-Wire Temperature

I searched for the correct device and found it in the test set A. I gona test it now. To be continued!

TD-er
Core team member
Posts: 8756
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: One button code lock

#18 Post by TD-er » 05 Jul 2023, 20:40

At least you know the iButton is working and properly connected, when the temperature plugin can 'see' it :)

Dick60
Normal user
Posts: 243
Joined: 11 Feb 2018, 17:35
Location: The Netherlands

Re: One button code lock

#19 Post by Dick60 » 05 Jul 2023, 21:01

ha ha, it is all logic. You are right, it working but this is what I see
752422: DS : iButton searching for address: 0f-ff-8f-47-0e-00-00-f7 [] found:
752522: DS : iButton searching for address: 0f-ff-8f-47-0e-00-00-f7
and this is repeating. What can I do with the info of the key found and how can i Stop the continuing searching for keys. The intervan is set to 60 .

TD-er
Core team member
Posts: 8756
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: One button code lock

#20 Post by TD-er » 05 Jul 2023, 21:26

Hmm now you assume I know how that plugin is working...

I just took a look at the code and noticed it is programmed to be a rather ... interesting design.

You should have the iButton present when opening the web interface page for that task and select the right key from the found devices.
Then save it.

It will be scanned 10x per second to see if that button is present.
When it is present or no longer present, it will generate an event when its detected state has changed since the last PLUGIN_READ call (every N seconds set as "Interval")

To be honest, that's a rather strange design decision as you need to have it pressed for > 1 second to have the event.

And I'm not even mentioning the probably high CPU load of how it is implemented.

User avatar
Ath
Normal user
Posts: 3519
Joined: 10 Jun 2018, 12:06
Location: NL

Re: One button code lock

#21 Post by Ath » 05 Jul 2023, 21:35

TD-er wrote: 05 Jul 2023, 21:26 It will be scanned 10x per second to see if that button is present.
When it is present or no longer present, it will generate an event when its detected state has changed since the last PLUGIN_READ call (every N seconds set as "Interval")

To be honest, that's a rather strange design decision as you need to have it pressed for > 1 second to have the event.
That's probably because these iButtons are (often) used the same way as a RFID tag, the 1 second hold-time is probably to be sure it's not triggered by accident, when quickly swiping the button close to the reader.
/Ton (PayPal.me)

TD-er
Core team member
Posts: 8756
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: One button code lock

#22 Post by TD-er » 05 Jul 2023, 21:40

But why not then generate an event when it is being scanned?
You need to make contact for a while, it isn't RF-ID.


And performing a full search to see what is present... 10x per second for each task you make to support multiple keys... is not really smart programming.

Dick60
Normal user
Posts: 243
Joined: 11 Feb 2018, 17:35
Location: The Netherlands

Re: One button code lock

#23 Post by Dick60 » 06 Jul 2023, 09:35

the discussion doesn't give me the impression if the iButton solution is a good oe. I am afraid that it will influence the overall performance of the other devices. I have to test that. Now I made an event. As soon as a certain key with ID (according the log "01-a3-be-8c-01-00-00-b5 [DS1990A]" is read, a test switch must be set to "0".

Code: Select all

on iButton#All do  // %eventvalue% is the actual value that triggered the event
  if %eventvalue1%=01-a3-be-8c-01-00-00-b5 [DS1990A]// ibutton to be found
GPIO,13,0 //test switch
    else
gpio,13,1
endif
  endon
Result: the key was read successful but the switch did not change. Also tried this id without the "[DS1990A]" but the result was the sam.

Code: Select all

on iButton#All do  // %eventvalue% is the actual value that triggered the event
  if %eventvalue1%=01-a3-be-8c-01-00-00-b5// ibutton to be found 
GPIO,13,0 //test switch
    else
gpio,13,1
endif
  endon

User avatar
Ath
Normal user
Posts: 3519
Joined: 10 Jun 2018, 12:06
Location: NL

Re: One button code lock

#24 Post by Ath » 06 Jul 2023, 09:39

You need to add a single asterisk * in the on iButton#All* do line, so the first argument isn't checked for being numeric, like this:

Code: Select all

on iButton#All* do  // %eventvalue% is the actual value that triggered the event
  if %eventvalue1%=01-a3-be-8c-01-00-00-b5 // ibutton to be found 
    GPIO,13,0 //test switch
  else
    gpio,13,1
  endif
endon
/Ton (PayPal.me)

TD-er
Core team member
Posts: 8756
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: One button code lock

#25 Post by TD-er » 06 Jul 2023, 10:08

It isn't setting the key, but only a 1 or 0 for that specific task.

So imagine you have a task named "dick60" and you name its task value "present", then the event will be something like this:

Code: Select all

dick60#present=1
I suggested to use your name as task name here, as I can assume a specific key being personal.

Dick60
Normal user
Posts: 243
Joined: 11 Feb 2018, 17:35
Location: The Netherlands

Re: One button code lock

#26 Post by Dick60 » 06 Jul 2023, 11:04

I cannot follow this, I keep the first event iButton#All* and create another event called Dick60#present like this

Code: Select all

on dick60#present=1 do
gpio,13,1
else 
gpio,13,0
endof
endon
but where is the connection with the first event?

TD-er
Core team member
Posts: 8756
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: One button code lock

#27 Post by TD-er » 06 Jul 2023, 11:10

You got the syntax wrong:

Code: Select all

on dick60#present do
  if %eventvalue1%=1
    gpio,13,1
  else 
    gpio,13,0
  endif
endon
Or even simpler:

Code: Select all

on dick60#present do
  gpio,13,%eventvalue1%
endon

Dick60
Normal user
Posts: 243
Joined: 11 Feb 2018, 17:35
Location: The Netherlands

Re: One button code lock

#28 Post by Dick60 » 06 Jul 2023, 11:17

hum, still struggling. This is what I have but see that the first event has the switch 13 . This cannot work in my opinion. I know, I do something wrong but what?

Code: Select all

on iButton#All* do  // %eventvalue% is the actual value that triggered the event
  if %eventvalue1%=01-a3-be-8c-01-00-00-b5 // Above this voltage the loader is turned on
GPIO,13,1
    else
GPIO,13,0
endif
  endon

on dick60#present do
  if %eventvalue1%=1
    gpio,13,1
  else 
    gpio,13,0
  endif
endon

TD-er
Core team member
Posts: 8756
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: One button code lock

#29 Post by TD-er » 06 Jul 2023, 11:25

How is the ibutton task being called and what is its task value being called?

Can you get the exact event from the logs?

Dick60
Normal user
Posts: 243
Joined: 11 Feb 2018, 17:35
Location: The Netherlands

Re: One button code lock

#30 Post by Dick60 » 06 Jul 2023, 11:39

this is what is in the log "EVENT: test#All=0" and that is the only one,

TD-er
Core team member
Posts: 8756
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: One button code lock

#31 Post by TD-er » 06 Jul 2023, 12:22

So the task is named "test" and you have checked the checkbox to combine it all in one event?

Dick60
Normal user
Posts: 243
Joined: 11 Feb 2018, 17:35
Location: The Netherlands

Re: One button code lock

#32 Post by Dick60 » 06 Jul 2023, 12:31

I feel dom, The name of the iBotton is Device: Input - iButton name: test and values: iButton. I only have the 2 scripts as mentioned before. Combine??? I have not see that option

TD-er
Core team member
Posts: 8756
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: One button code lock

#33 Post by TD-er » 06 Jul 2023, 12:50

The task name is the name you can give to a task yourself...
That's why I suggested "dick60" as taskname.
But if you have named it "test" that's fine.

The value named "iButton" is also fine.

Just make sure the "Single event with all values:" is unchecked.

So the event will then be: test#iButton.
When that checkbox ("Single event with all values:") is checked, the event will be: test#All

So then we end up with this:

Code: Select all

on test#iButton do
  if %eventvalue1%=1
    gpio,13,1
  else 
    gpio,13,0
  endif
endon

Dick60
Normal user
Posts: 243
Joined: 11 Feb 2018, 17:35
Location: The Netherlands

Re: One button code lock

#34 Post by Dick60 » 06 Jul 2023, 13:01

but this part of reading the value of the key, where is that placed?
if %eventvalue1%=01-a3-be-8c-01-00-00-b5

User avatar
Ath
Normal user
Posts: 3519
Joined: 10 Jun 2018, 12:06
Location: NL

Re: One button code lock

#35 Post by Ath » 06 Jul 2023, 14:40

That was a misconception in my previous response :oops:, the event is called with the result of the state from the button that is selected in the task (you can only pick 1 of the addresses, other iButtons won't respond).
Also, the task should generate an event when the state changes, so from 0 to 1 or from 1 to 0. And that new 0/1 state is the value of %eventvalue1%.

As you can only select 1 iButton-address in the task, only that iButton will be handled, other iBottons presented to the reader will not cause any events.

To be able to handle multiple iButtons with a single task, or a large(-ish) number of iButtons (you can only have 12 tasks on an ESP8266, or 32 on an ESP32 based ESPEasy), the plugin code needs to be changed changed (as might be a good idea anyway, as TD-er pointed out before).
/Ton (PayPal.me)

Dick60
Normal user
Posts: 243
Joined: 11 Feb 2018, 17:35
Location: The Netherlands

Re: One button code lock

#36 Post by Dick60 » 06 Jul 2023, 15:50

I tested this solution and works fine but I prefer to wait for a better solution because I do not like the limitations of 1 button. I can buy some RW buttons but a reader to give them the same ID, is quit expensive and if it is correct, you only use it once, during the RW activity.THanks for this discussion! Hope a better solution is presented soon :shock:

TD-er
Core team member
Posts: 8756
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: One button code lock

#37 Post by TD-er » 06 Jul 2023, 17:13

You can create a second task with the same plugin (and a different task name) where you select a different tag.

Dick60
Normal user
Posts: 243
Joined: 11 Feb 2018, 17:35
Location: The Netherlands

Re: One button code lock

#38 Post by Dick60 » 07 Jul 2023, 19:04

I wanted to test the last remark of the second ibutton. It works perfect. 2 Different ibuttons, 1 reader and 2 diffrent events. Thanks for the solution. I probably build it on an esp32 because of the cpu load.

TD-er
Core team member
Posts: 8756
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: One button code lock

#39 Post by TD-er » 07 Jul 2023, 21:42

Not sure if that will make a lot of difference here (ESP32 vs ESP8266) as it isn't a CPU-cycles problem, but a poor design choice based on lots of timeouts.

I will try to have a look at it later this weekend...

Dick60
Normal user
Posts: 243
Joined: 11 Feb 2018, 17:35
Location: The Netherlands

Re: One button code lock

#40 Post by Dick60 » 08 Jul 2023, 09:40

I would appreciate that but also enjoy the nice weather :lol:

TD-er
Core team member
Posts: 8756
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: One button code lock

#41 Post by TD-er » 08 Jul 2023, 15:50

tomorrow will have rain (I hope..)

Dick60
Normal user
Posts: 243
Joined: 11 Feb 2018, 17:35
Location: The Netherlands

Re: One button code lock

#42 Post by Dick60 » 11 Jul 2023, 22:08

is there any development in the code optimalisation

TD-er
Core team member
Posts: 8756
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: One button code lock

#43 Post by TD-er » 11 Jul 2023, 22:19

Nope, not yet.
Have been busy looking into a memory leak which makes units reboot after only days...

Dick60
Normal user
Posts: 243
Joined: 11 Feb 2018, 17:35
Location: The Netherlands

Re: One button code lock

#44 Post by Dick60 » 19 Aug 2023, 07:33

Just curious if there is any development in the optimalisation of the code? No hurry but still interested!

TD-er
Core team member
Posts: 8756
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: One button code lock

#45 Post by TD-er » 19 Aug 2023, 10:37

Not yet, as I have been focussing on energy meters in the last 2 months (and stability issues)

But good to have a reminder, as I have to admit, it kinda slipped my mind.

Dick60
Normal user
Posts: 243
Joined: 11 Feb 2018, 17:35
Location: The Netherlands

Re: One button code lock

#46 Post by Dick60 » 17 Sep 2023, 12:35

Still no time for checking the code? No hurry but only a reminder.

TD-er
Core team member
Posts: 8756
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: One button code lock

#47 Post by TD-er » 17 Sep 2023, 14:05

Nope not yet, have been extremely busy with other stuff I really didn't wanted to spend time on....

Dick60
Normal user
Posts: 243
Joined: 11 Feb 2018, 17:35
Location: The Netherlands

Re: One button code lock

#48 Post by Dick60 » 17 Sep 2023, 19:11

No problem, See it as a reminder. :P

Dick60
Normal user
Posts: 243
Joined: 11 Feb 2018, 17:35
Location: The Netherlands

Re: One button code lock

#49 Post by Dick60 » 19 Oct 2023, 22:13

Here my reminder for the Ibutton. I know you have more to do but again, it is a reminder :D

Dick60
Normal user
Posts: 243
Joined: 11 Feb 2018, 17:35
Location: The Netherlands

Re: One button code lock

#50 Post by Dick60 » 26 Oct 2023, 10:18

I try to implement the 1 button solution mentioned earlier. It is a good temporary solution for my Ibutton. I implemented on on esp8266 with the latest firmware. In the log I get this error:
5332292: ACT : (restricted) restrict,1=11 and 1=3
5332297: Command unknown: 1=11 and 1=3
5332300: ACT : let,1,0
5332305: ACT : GPIO,12,0
5332308: GPIO: port#12: set to 0
5332838: SW : LongPress: GPIO= 14 State=0 Output value=11
5332844: EVENT: switch#State=11
5332860: Rules : Prefix command with 'restrict': restrict,11=11 and 0=3

Any Idea?

The code of the pushbutton script:

Code: Select all

5332292: ACT : (restricted) restrict,1=11 and 1=3
5332297: Command unknown: 1=11 and 1=3
5332300: ACT : let,1,0
5332305: ACT : GPIO,12,0
5332308: GPIO: port#12: set to 0
5332838: SW : LongPress: GPIO= 14 State=0 Output value=11
5332844: EVENT: switch#State=11
5332860: Rules : Prefix command with 'restrict': restrict,11=11 and 0=3

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 43 guests