pyzk
pyzk copied to clipboard
Corrupted and wrong data on MB560-VL
Hello,
when i try to get the attendance data from my device using get_attendance(), i get corrupted data.
this is my function it works fine with other devices but not with the MB560-VL :
#!/usr/bin/python3
from zk import ZK import json import argparse import sys import traceback import time
def MyFunction():
try:
# ------------------------------- les arguments ------------------------------ #
parser = argparse.ArgumentParser(description='ZK Basic Reading Tests')
parser.add_argument('-a', '--address', help='PYZK IP', default=None)
parser.add_argument('-p', '--port', type=str, help='device port [4370]', default=4370)
parser.add_argument('-pro', '--protocole', type=str, help='protocole', default='tcp')
parser.add_argument('-ping', '--ping', type=str, help='if ping or not', default='no_ping')
args = parser.parse_args()
conn = None
# Maximum number of retry attempts
MAX_RETRIES = 3
retries = 0
tout_les_pointages = []
attendance = None
# --------------------------- les autres variables --------------------------- #
force_udp = True if args.protocole=="udp" else False
ping = True if args.ping=="no_ping" else False # ommit_ping = True donc pas de ping
while retries < MAX_RETRIES:
try:
# create ZK instance
zk = ZK(args.address, port=int(args.port), timeout=10, password=0, force_udp=force_udp, ommit_ping=ping)
# connect to device
conn = zk.connect()
# Si la connection est ok
if conn:
# disable device, this method ensures no activity on the device while the process is run
conn.disable_device()
# On stoque les pointages dans une liste
attendance = conn.get_attendance()
for att in attendance:
tout_les_pointages.append({'created_at':"{}".format(att.timestamp),'matricule':att.user_id,'pointeuse':args.address})
# re-enable device after all commands already execute
conn.enable_device()
conn.disconnect()
conn = None
# Renvoie du resultat
print(json.dumps({'tout_les_pointages':tout_les_pointages,'connexion':'ok'}))
break # exit the while loop when connection and operations are successful
# Si la connection n'est pas ok
else:
conn = None
zk = None
retries += 1
time.sleep(3) # wait for 3 second before retrying
# if an exception occurs during the connection or operation, print the error and retry
except:
conn = None
zk = None
retries += 1
time.sleep(3) # wait for 3 second before retrying
# If we've exhausted the retry attempts, print an error message
if retries == MAX_RETRIES:
print(json.dumps({'connexion':'no', 'error':'maximum retry attempts reached'}))
except :
exc_info = sys.exc_info()
print(json.dumps({'connexion':'no' ,'erreur':'except','message':''.join(traceback.format_exception(*exc_info))}))
#Appel à la fonction de syncrhonisation MyFunction() it return something like :
{ "tout_les_pointages": [ { "created_at": "2023-06-27 18:48:54", "matricule": "3", "pointeuse": "device_one" }, { "created_at": "2000-01-01 00:00:00", "matricule": "55", "pointeuse": "device_one" }, { "created_at": "2000-01-01 00:00:00", "matricule": "", "pointeuse": "device_one" }, { "created_at": "2000-02-08 16:26:04", "matricule": "", "pointeuse": "device_one" }, { "created_at": "2027-10-09 22:21:51", "matricule": "", "pointeuse": "device_one" }, { "created_at": "2000-01-01 00:00:04", "matricule": "", "pointeuse": "device_one" }, { "created_at": "2000-01-01 00:00:00", "matricule": "", "pointeuse": "device_one" } ], "connexion": "ok" } "Firmware Version": "Ver 6.60 Aug 19 2021", "Device Name": "MB560-VL/ID"