Problem with perimeter detection

Hi,

I’m working on a project and I need to use the perimeter detection. I’m using the python library, but I doesn’t understand how to use the library.
I made a script to display the information and it’s works perfectly. (Here’s the script)

import zymkey
import time

zymkey.client.clear_perimeter_detect_info()
while True:
    print(zymkey.client.get_perimeter_detect_info())
    time.sleep(1)

But when I tried to set an event action and retreive this event, the function wait_for_perimeter_event() always return None. Here’s the script I made :

import zymkey
import time

print(zymkey.client.clear_perimeter_detect_info())
print(zymkey.client.set_perimeter_event_actions(1, action_notify=True, action_self_destruct=False))
print(zymkey.client.set_perimeter_event_actions(0, action_notify=True, action_self_destruct=False))
print(zymkey.client.clear_perimeter_detect_info())
while True:
    res = zymkey.client.wait_for_perimeter_event()
    print(res)
    if not res:
        print(zymkey.client.get_perimeter_detect_info())
        zymkey.client.clear_perimeter_detect_info()
    time.sleep(1)

Can you tell me what I did wrong ?
Thanks in advance !

wait_for_perimeter_event does not return anything. It raises an exception if a timeout occurs. If you do not specify a timeout, then it will wait forever. Your script should run correctly if you restructure it like this:

import zymkey
import time

print(zymkey.client.clear_perimeter_detect_info())
print(zymkey.client.set_perimeter_event_actions(1, action_notify=True, action_self_destruct=False))
print(zymkey.client.set_perimeter_event_actions(0, action_notify=True, action_self_destruct=False))
print(zymkey.client.clear_perimeter_detect_info())
while True:
    zymkey.client.wait_for_perimeter_event()
    print(zymkey.client.get_perimeter_detect_info())
    zymkey.client.clear_perimeter_detect_info()
    time.sleep(1)

If you prefer not to have the wait_for_perimeter_event block forever, you can specify a timeout, but should catch the timeout exception, something like this:

import zymkey
import time

print(zymkey.client.clear_perimeter_detect_info())
print(zymkey.client.set_perimeter_event_actions(1, action_notify=True, action_self_destruct=False))
print(zymkey.client.set_perimeter_event_actions(0, action_notify=True, action_self_destruct=False))
print(zymkey.client.clear_perimeter_detect_info())
while True:
    try:
        zymkey.client.wait_for_perimeter_event(timeout_ms=1000)
    exception zymkey.exceptions.ZymkeyTimeoutError:
        print("wait_for_perimeter_event timed out. Doing other stuff...")
        # Do other stuff here...
        continue
    print(zymkey.client.get_perimeter_detect_info())
    zymkey.client.clear_perimeter_detect_info()
    time.sleep(1)