Using Perimeter Detect

Perimeter detect does already work with battery backup,

Is it necessary to configure the device in any way for this to happen? I’m currently testing the Perimeter detect feature and the system doesn’t seem to detect any event if its not powered by the Pi. At least the information returned by zymkey.module.Zymkey().get_perimeter_detect_info() doesn’t change (returns [0L, 0L] even if I breach both channels when the system is powered down).
The Perimeter detect feature works perfectly when the pi is powered (even on halt). All functions seem to work fine. I’m cleaning the detect info (clear_perimeter_detect_info()) before turning down pi’s power and breaching the perimeter.
Is there any step I’m missing or any other way I could get this information?

Thanks by advance.

Sorry to ask the obvious question - but do you have a battery inserted into the Zymkey. And if yes, do you have a way to measure the voltage on it.

That’s ok. Thank you for the quick response.
Yes, the battery ia inserted correctly. Unfortunatly I won’t be able to measure its voltage or test again within a week. My main concern was the need of different configurations. I’ll try using a different battery cell and will post here the voltage value when I get the chance to acquire it.
Thanks!

Im running this code above with
gcc -o Test Test.c -lzk_app_utils -lpthread -I /usr/include/zymkey

I’ve tied all the Perimeter Lines together to make sure there are no breaks.

I’m get
Tamper Detect Input 1 = 1574491337
Tamper Detect Input 2 = 1574491337
Tamper Detect Input 1 = 1574491426
Tamper Detect Input 2 = 1574491426
Tamper Detect Input 1 = 1574491427
Tamper Detect Input 2 = 1574491427

Not sure why there is an event triggered since all the perimeter lines are closed.

Hi

I need some help with the Test I ran above… It is not detecting properly.

Here are my results:
Im running this code above with
gcc -o Test Test.c -lzk_app_utils -lpthread -I /usr/include/zymkey

I’ve tied all the Perimeter Lines together to make sure there are no breaks.

I’m get
Tamper Detect Input 1 = 1574491337
Tamper Detect Input 2 = 1574491337
Tamper Detect Input 1 = 1574491426
Tamper Detect Input 2 = 1574491426
Tamper Detect Input 1 = 1574491427
Tamper Detect Input 2 = 1574491427

Not sure why there is an event triggered since all the perimeter lines are closed.

And the code:
#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);
	}
}

}

@cjh39 Can you please clarify what you mean by your statement below. Thx

I meant that the inner and outer perimeter lines
Are in a loop and should not cause a perimeter event

Sorry to be pedantic, but we have seen all sorts of odd wiring. Please confirm you have connected as follows;

P1A is connected to P1B
P2A is connected to P2B
P1(AorB) is NOT connected to any P2(AorB)

Thanks

Yes that’s correct I have two loops with p1 not connected to anything

@cjh39

At the start of your post you state

and then you state

These appear contradictory. Can you share a hand sketch of what you have wired to what. Thx

Hi,
Here is the picture of the 2 loops.

The cable I’m using is a 5 pin
https://www.amazon.com/gp/product/B07PPXMTLL/ref=ppx_yo_dt_b_asin_title_o02_s00?ie=UTF8&psc=1

The cable you are using does not break out the id pin of the connector. It breaks out the cable shield instead.

This means that you are connecting shield to “D+” (pin 3 on usb connector, Perim2 pullup) and “+” (pin 1 on usb connector, no connection to zymkey) to “D-” (pin 2 on usb connector, Perim1 pullup). This explains why you are seeing the broken circuit.

Since your breakout cable does not break the id pin out, the only perimeter detect circuit you can actually get working with this cable is Perim1: connect lug 1 ("-", pin 5 on usb connector) to lug 3 (“D-”, pin 2 on usb connector).

Hi Scott,

Thanks for the help. I ordered the new cable and it seems to work.
The test program gets a segmentation fault after a couple seconds.

Is it possible to fix this ?

#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, 100000);
            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);
            }
    }

}

hi ,

i still dont cut the lock. still in development mode. i set the event as notify. but i dont understand the value of temper detect input? my value when p1 and p2 connected is between 800-900.

and when i disconnect p2, the value not change. how can i detect when the wire is disconnected?

saufy

Is there a way to call wait_for_perimeter_event() asynchronously?

Also, when I call wait_for_perimeter_event(timeout_ms=0), I get AssertionError. Why is that?

Wanted to confirm if the zymkey babbling behavior is expected on making a zkunlockifs call on /var/lib/zymbit/key.bin.lock ?
What happens in self-destruct mode if this call is made from the pi?

I would suggest that you create a thread which calls wait_for_perimeter_event with a non-zero timeout.

The timeout of 0 makes no sense for a blocking wait since nothing is returned from wait_for_perimeter_event. If you want to query the status of the perimeter event continuously, you could just call get_perimeter_detect_info.

Are you calling zkunlockifs manually? This utility should never be called during normal operation. It is only intended to be called as part of the pi boot sequence for encrypted root file system in initrd.img.

Sure! Mentioned about timeout value of 0 because it was mentioned in the documentation and I was wondering how it can be used. Documention - " This function blocks the calling thread unless called with a timeout of zero"

Yes, calling it manually only for testing. I see that the zymkey blabbles, but it can still detect a perimeter breach. How can I detect zymkey blabble programmatically? This can give insight if someone tried to do an intrusive operation with zymkey.