fananimi / pyzk

Unofficial library of zkteco fingerprint attendance machine
GNU General Public License v2.0
498 stars 330 forks source link

BULK FINGERPRINT TEMPLATES UPLOAD #146

Closed muneebmalik78 closed 1 year ago

muneebmalik78 commented 2 years ago

Hi, I am using pyzk for uploading the large amount of fingerprint templates to ZK-TECO device. However this process take long time and as the number of template increases the uploading time per user keeps on increasing and the user interactivity halts as well. Is there a way where I can upload a large amount of templates in a single request. I was going through the ZK Teco SDK Development manual states it is possible. Can anyone help?

ZK-Teco Device: https://www.zkteco.com.pk/product_detail/K40.html

Thanking in advance

kurenai-ryu commented 2 years ago

I can't find a suitable command to send bulk data to the device, if you have tested it with the official zk software, try capturing the communication process of that particular task, and publish the pcap file to analyze it. (ans reopen the ticket)

muneebmalik78 commented 2 years ago

Greetings @kurenai-ryu, Hope you're doing good. Sorry for late reply. I have tested the user & template uploading but in official ZK software there were two different modes to do it.

  1. Normal Mode (without high data rate mode)

Upload_FP_Users_Normal Mode_E

  1. High Rate Mode (with high data rate mode)

Upload_FP_Users_High_Rate Mode_E

From the above Images if we calculate the time difference of start and finish, the time it took to upload 150 users for Normal Mode is almost 1 minute and for that of High Rate Mode its almost 10 seconds for same number of users. The High Data Rate Mode is required here I guess. Please let me know if there is anything else required from my side.

Number of Users Uploaded : 150 User ID's: 1001 -->> 1150 User Name's: Same as User ID's Templates Per User: -->> 2 Finger ID's: -->> 3 and 6 for all users

Target ZK Machine IP: 192.168.0.200 Source PC IP: 192.168.0.203

PCAP Files: PCAP Files

ZK-Teco Device: https://www.zkteco.com.pk/product_detail/K40.html

ZK Software: ZKTime5.0

kurenai-ryu commented 2 years ago

ok, I checked the files and indeed there're some undocumented commands used there. i think the data is about 150 users, so it makes it difficult to analyse the data packets.

if you can please perform some scenarios:

i think the first 4 cases are essential, but the others can help to confirm the data structure of the new commands.

muneebmalik78 commented 2 years ago

Hi @kurenai-ryu, I hope you're doing good. So I have updated the PCAP Files in which I have managed to perform all the test case scenarios you have asked. In Addition I have added one more test case scenario as below

Please go through the README.md file in every directory, this will help you understand the test cases distributions per directory. Hope this will help you in back tracing the commands and new structures, let me know if you need me to provide any other test cases.

PCAP Files

kurenai-ryu commented 2 years ago

thank you @muneebmalik78 your scenarios helped me to make a proposal, but I need some help to test it

i create a PR in this repo https://github.com/fananimi/pyzk/pull/148 and you can find my develop branch here https://github.com/kurenai-ryu/pyzk/tree/issue/146/high-rate-upload

I added some info in the README.md you need to create a list of lists/tuples (of user,list of finger templates), similar to:

usertemplates = [
    (user_1, [user_finger_1, finger_2]),
    (user_2, [finger_3]),
    (user_3, []), #this one only user data
    ...
]
conn.HR_save_usertemplates(usertemplates)

I hope you can test it and tell me if it works correctly

(if not, please include the pcap file to analyse the packet structure, with something small like 2 users, 2 fp)

kurenai-ryu commented 2 years ago

I also added flag -g to test_backup_restore but I hope you can test it with a small custom script.

muneebmalik78 commented 2 years ago

HI @kurenai-ryu, Thank you for the support and PR. So I have tested it with the changes and there were two things right away that needs to be fixed before merging which are as below

Targeted Change File name: base.py

  1. Replace if not isinstance(fingers, Finger): with if not isinstance(finger, Finger): line # 971
  2. Replace start += len(tfp) with tstart += len(tfp) line # 975

I had to make these changes to make the code work. Meanwhile, I will test and let you know about the results.

Thank you.

kurenai-ryu commented 2 years ago

thank you @muneebmalik78 , I committed the fix