Using Perimeter Detect


#22

I just tried to test the zkWaitForPerimeterEvent function but this is quite the same: works well during the first rounds, but just “failed” suddenly: no flash anymore, not even detection of a perimeter wire breach :frowning:


#23

Hi @Tgratier,

Sorry it took so long for me to get back to you. Unfortunately, you have come across a bug with our host side software. This bug causes the Zymkey to be unresponsive for 5 minutes after a 10 minute period. In other words, the Zymkey will respond to commands for 10 minutes, then become unresponsive for 5 minutes, and then the cycle repeats.

We releasing an update to our Zymkey repository this Friday. Sorry for the inconvenience.

To answer your other question, the total number of timestamps returned from zkGetPerimeterDetectInfo corresponds to the total number of perimeter detect circuits. Since Zymkey 4i has 2 perimeter detect circuits, zkGetPerimeterDetectInfo will always return 2 for num_timestamps, regardless of whether an action has been set for a given perimeter detect input.


#24

Ok cool! Thx for your answer (one more time).

By the way, where can we check each time you update on the repository? Just in visiting https://s3.amazonaws.com/zk-sw-repo/ ?


#25

@Tgratier The latest is up there now.


#26

ok thx.

I just made the update with:
sudo apt-get update
then
sudo apt-get install libzk libzymkeyssl zkbootrtc zkifc zkapputilslib
and it well upgraded the 5 items, then I reboot the pi.

I am sorry to tell you that I still have a strange behavior.
It still works during the first rounds, like just during 30seconds of tests (by the way the led of the Zymkey doesn’t work anymore too during this period). If I reboot the pi it will works properly immediately after I executed the code.

I know in “real life” that my “security routine” should be to quit my software at the first breach detection. But I must proceed to a lot of tests, so that’s why I am trying to use the zkClearPerimeterDetectEvents function.


#27

@Tgratier,

I’m not sure what is going on here. We have not seen this issue in our validation testing. However, we will run through some test code that looks similar to yours early next week.

In the meantime, I think the best way to check the perimeter detect would look something like this:

int num_timestamps = 0;
uint32_t *tab_event;
zkCTX ctx;

if(zkOpen(&ctx) <0)
{
	printf("Unable to setup RTC module\n");
	return 0;
}
zkSetPerimeterEventAction(ctx, 0, ZK_PERIMETER_EVENT_ACTION_NOTIFY);

while(1)
{
	/*
	 *	do_something
	 */ 

	int res = zkWaitForPerimeterEvent(ctx, 1000);
	if (!res)
	{
		zkGetPerimeterDetectInfo(ctx, &tab_event, &num_timestamps);
		if (tab_event[0])
		{
			printf("num timestamp = %d\n", num_timestamps);
			printf("Last event = %ld\n", tab_event[0]);
			zkLEDFlash(ctx, 500, 500, 4);
			zkClearPerimeterDetectEvents(ctx);
		}
	}
}

Could you please try this code and see if it works better for you?


#28

Well, I still have some troubles if I am using the code you sent me. I also have sudden segfault…

BUT, I tried to investigate about my problem and found that both code (the first I posted and the one you wrote) work well if I put some sleep delay between two check.
In my first code I only use a one second delay, but it seems to work good if I put longer delay like 5 seconds delay. Could you explain this? Is this like, a I2C bus limitation? Like if the bus would be “full” and the loose the synchro if it is too much sollicitation?


#29

When trying to use:

import zymkey
zymkey.client.set_perimeter_event_actions ( channel = 0, action_notify = True , action_self_destruct = True )

I allways receive:

File “”, line 1, in
_ File “/usr/local/lib/python2.7/dist-packages/zymkey/module.py”, line 567, in set_perimeter_event_actions_
_ raise AssertionError(‘bad return code {!r}’.format(ret))_
AssertionError: bad return code -110

I can not find the reason it stopped working.


#32

@Tgratier We are able to reproduce your issue and are looking into it. We’ll post back when we have a fix.


#33

@Tgratier just to give you some status on the ticket we filed for your issue: we have a fix and it is going through validation. We expect to have a new release early next week.


#34

Ok nice, and thx again for your help!


#35

@Tgratier we have put a new release up on our repo which addresses your issue.

Here is the complete test code we used to verify your problem and validate your fix:

#include <stdlib.h>
#include <stdio.h>
#include <zymkey/zk_app_utils.h>

int main(int argc, char* argv[])
{
	int num_timestamps = 0;
	uint32_t *tab_event;
	zkCTX ctx;

	if(zkOpen(&ctx) <0)
	{
		printf("Unable to setup RTC module\n");
		return 0;
	}
	zkSetPerimeterEventAction(ctx, 0, ZK_PERIMETER_EVENT_ACTION_NOTIFY);
	zkSetPerimeterEventAction(ctx, 1, ZK_PERIMETER_EVENT_ACTION_NOTIFY);

	while(1)
	{
		int res = zkWaitForPerimeterEvent(ctx, 1000);
		if (!res)
		{
			zkGetPerimeterDetectInfo(ctx, &tab_event, &num_timestamps);
			int ii;
			for (ii = 0; ii < 2; ii++)
			{
				if (tab_event[ii])
				{
					printf("Tamper Detect Input  %d = %ld\n", ii + 1, tab_event[ii]);
				}
			}
			zkLEDFlash(ctx, 500, 500, 4);
			zkClearPerimeterDetectEvents(ctx);
		}
	}
}

Of course, your original code snippet should work as well.

Hope this helps and if you need any further assistance, please let us know


#36

First, thank you again to help me.

I am sorry but I still have exactly the same problem:

  1. I run the install script to update the deposit and install your new release
  2. I first tried my old code but after few tries I test the version you gave me. I just comment the perimeter event action notify for the “1” wire, but it stills detect a new timestamp event
  3. the delay in the zkWaitForPerimeterEvent function is not working anymore. I can put 1000 or 5000 but it doesn’t change anything.
  4. after few rounds, like ten or fifteen I have a segfault. Then, I must restart the device to being able to “play” with the zymkey again. If I don’t restart the system, the zkOpen(&ctx) stills works but after the calling the zymkey doesn’t blink anymore, or detect any event.

#37

Just to be sure you know, the delay in zkWaitForPerimeterEvent is the maximum amount of time to wait for an event to arrive. If there is an event waiting, the call returns as soon as it can with a 0 status. If it times out, it will return a -110 (-ETIMEDOUT). In the example code that I provided, the messages do not get printed out unless perimeter events are detected which means that your loop is open. Have you properly closed the loop PERIM 1 input (pins 4 and 2 on the microUSB connector)?

I apologize, but it looks like our repository did not update correctly last night. It is current now. You should be able to upgrade using the following commands:

sudo apt-get update
sudo apt-get install --only-upgrade zkifc


#38

OK now it seems to be perfect after the new update. Thx!


#39

Thanks, it also works for me so far.


#40

Sorry, the problem is back.
System is fully updated, also xkifc, and client.set_perimeter_event_actions fails again with the same message.

Help!


#41

Hi @Iker,

Is your Zymkey locked? If so, it is only possible to set perimeter event actions one time after the lock tab has been cut.


#42

Yes it is cut.
I could only modify once, after then it fails as before the update.


#43

Meanwhile, is there any command I can use to delete key from command line?