From 55d13af4cb4db4113708ccb697a1e83cf753539d Mon Sep 17 00:00:00 2001 From: wastlmuc <101905304+wastlmuc@users.noreply.github.com> Date: Fri, 13 Dec 2024 23:30:40 +0100 Subject: [PATCH] Fix card swipe detection issue after NTP update After a Jukebox updates its wall clock (e.g., via NTP), a card swipe may be incorrectly detected. Using time.monotonic can prevent this issue. --- scripts/daemon_rfid_reader.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/daemon_rfid_reader.py b/scripts/daemon_rfid_reader.py index a7e5cf78f..587586d22 100755 --- a/scripts/daemon_rfid_reader.py +++ b/scripts/daemon_rfid_reader.py @@ -34,7 +34,7 @@ sspc = open('../settings/Second_Swipe_Pause_Controls', 'r') sspc_nodelay = sspc.readline().strip() previous_id = "" -previous_time = time.time() +previous_time = time.monotonic() # get swipe or place configuration value sop = open('../settings/Swipe_or_Place', 'r') @@ -94,7 +94,7 @@ def handler(signum, frame): # start the player script and pass on the cardid (but only if new card or otherwise # "same_id_delay" seconds have passed) if cardid is not None: - if cardid != previous_id or (time.time() - previous_time) >= float(same_id_delay) or cardid in str(ids): + if cardid != previous_id or (time.monotonic() - previous_time) >= float(same_id_delay) or cardid in str(ids): logger.info('Trigger Play Cardid={cardid}'.format(cardid=cardid)) subprocess.call([dir_path + '/rfid_trigger_play.sh --cardid=' + cardid], shell=True) previous_id = cardid @@ -105,7 +105,7 @@ def handler(signum, frame): same_id_delay=same_id_delay )) - previous_time = time.time() + previous_time = time.monotonic() except OSError as e: logger.error('Execution failed: {e}'.format(e=e))