Giter Club home page Giter Club logo

node-zklib's Introduction

node-zklib

install

 npm install --save node-zklib
 or yarn add node-zklib
const ZKLib = require('./zklib')
const test = async () => {


    let zkInstance = new ZKLib('10.20.0.7', 4370, 10000, 4000);
    try {
        // Create socket to machine 
        await zkInstance.createSocket()


        // Get general info like logCapacity, user counts, logs count
        // It's really useful to check the status of device 
        console.log(await zkInstance.getInfo())
    } catch (e) {
        console.log(e)
        if (e.code === 'EADDRINUSE') {
        }
    }


    // Get users in machine 
    const users = await zkInstance.getUsers()
    console.log(users)


    // Get all logs in the machine 
    // Currently, there is no filter to take data, it just takes all !!
    const logs = await zkInstance.getAttendances()
    console.log(logs)


    const attendances = await zkInstance.getAttendances((percent, total)=>{
        // this callbacks take params is the percent of data downloaded and total data need to download 
    })

     // YOu can also read realtime log by getRealTimelogs function
  
    // console.log('check users', users)

    zkInstance.getRealTimeLogs((data)=>{
        // do something when some checkin 
        console.log(data)
    })



    // delete the data in machine
    // You should do this when there are too many data in the machine, this issue can slow down machine 
    zkInstance.clearAttendanceLog();
    
    // Get the device time
    const getTime = await zkInstance.getTime();
		  console.log(getTime.toString());

    // Disconnect the machine ( don't do this when you need realtime update :))) 
    await zkInstance.disconnect()

}

test()

 
    async executeCmd(command, data=''){
        return await this.functionWrapper(
            ()=> this.zklibTcp.executeCmd(command, data),
            ()=> this.zklibUdp.executeCmd(command , data)
        )
    }

    // unlock the door  
    executeCmd(CMD.CMD_UNLOCK, '')

node-zklib's People

Contributors

caobo171 avatar csulit avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

node-zklib's Issues

RangeError [ERR_OUT_OF_RANGE]: The value of "offset" is out of range. It must be >= 0 and <= 4. Received 24

I am getting the following error and unable to understand the reason for its occurrence.
I tried to find solutions on Google but different people are facing this issue for entirely different applications.

Node Version: 17.0.0

The code execute perfectly till ok tcp

Error:

ZKError {
  err: RangeError [ERR_OUT_OF_RANGE]: The value of "offset" is out of range. It must be >= 0 and <= 4. Received 24
      at new NodeError (node:internal/errors:371:5)
      at boundsError (node:internal/buffer:86:9)
      at Buffer.readUInt32LE (node:internal/buffer:220:5)
      at Buffer.readUIntLE (node:internal/buffer:178:17)
      at ZKLibTCP.getInfo (C:\Users\shame\OneDrive\Desktop\AMS\zklibtcp.js:459:26)
      at processTicksAndRejections (node:internal/process/task_queues:96:5)
      at async ZKLib.functionWrapper (C:\Users\shame\OneDrive\Desktop\AMS\zklib.js:23:38)
      at async ZKLib.getInfo (C:\Users\shame\OneDrive\Desktop\AMS\zklib.js:182:16)
      at async test (C:\Users\shame\OneDrive\Desktop\AMS\index.js:10:17) {
    code: 'ERR_OUT_OF_RANGE'
  },
  ip: '192.168.18.2',
  command: '[TCP] undefined'
}

Error when users registered in device is too large?

ZKError {
  err: RangeError [ERR_OUT_OF_RANGE]: The value of "offset" is out of range. It must be >= 0 and <= 4. Received 24
      at boundsError (internal/buffer.js:76:9)
      at Buffer.readUInt32LE (internal/buffer.js:210:5)
      at Buffer.readUIntLE (internal/buffer.js:168:17)
      at ZKLibTCP.getInfo (C:\Users\csulit\Documents\node-zklib-master\zklibtcp.js:461:22)
      at processTicksAndRejections (internal/process/task_queues.js:97:5)
      at async ZKLib.functionWrapper (C:\Users\csulit\Documents\node-zklib-master\zklib.js:23:38)
      at async ZKLib.getInfo (C:\Users\csulit\Documents\node-zklib-master\zklib.js:182:16)
      at async test (C:\Users\csulit\Documents\node-zklib-master\test.js:10:15) {
    code: 'ERR_OUT_OF_RANGE'
  },
  ip: '192.168.139.81',
  command: '[TCP] undefined'
}

Logs writing should be controllable

There is an issue whereby logs are being written without a way to control them. There should be an option to control writing of error logs; the path and whether to write the logs or not.

Getting Attendance Data

When I get data using getAttendance() function and console log it:

showing result:

[Object Object], [Object Object]

how to read it

timeout error

When I put this script in cron job . after some cron jobs attempts it then fails to connect to the device.

get attendance timeout with large amounts of data

Someone could answer me that it is because when downloading large amounts of the device it takes out different amounts depending on the moment, I get the idea that it could be the timeout implemented, of the internet connection or it could be something different.

Currently I try to get the data from the log and it reaches the amount of 19k, but when I change the timeout time the amounts change and do not match the amount that comes from the info function.

pd: sorry for my bad ENG.

This log showed that you ran into TIMEOUT error ,and just that ...

This log showed that you ran into TIMEOUT error ,and just that ...
You need to provide more info about this situation like what 's your type of device , and make sure your ip is correct , your network is available and there's no other device connecting with this device ( because TCP connect doesn't allow concurrents connecting)

Originally posted by @caobo171 in #8 (comment)

More features

Hoping to see more features like

connect(callback) -> To Connect in machine.
disconnect() -> Disconnect connection with machine.
serialNumber(callback) -> Get serial number machine.
version(callback) -> Get version of machine.
enableDevice(callback) -> Enable the device.
disableDevice(callback) -> Disable the device.
getAttendance(callback) -> Get attendance data.
clearAttendanceLog(callback) -> Clear the attendance logs from device.
getTime(callback) -> Get time of machine.
setTime(value, callback) -> Set time in machine.
getUser(callback) -> Get all user in machine.

Timeout Error

check text [314] TIMEOUT ERROR
(node:7844) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'subarray' of null
at C:\Users\it\Documents\GitHub\biometric\node_modules\node-zklib\zklibtcp.js:213:46
(node:7844) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:7844) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
check text [374] Error: TIMEOUT ERROR
check attendances { data: [], err: 'Error: TIMEOUT ERROR' }
check users { data: [], err: 'TIMEOUT ERROR' }

https://snipboard.io/LoQyDG.jpg

getRealtimeLogs not working

Here my code

const ZKLib = require('./zklib')

let machine_ip = '192.168.192.168';

const test = async () => {
    let zkInstance = new ZKLib(machine_ip, 4370, 10000, 4000);
    try {
        await zkInstance.createSocket()
        console.log(await zkInstance.getInfo())
    } catch (e) {
        console.log("init", e);
    }

    try{
        zkInstance.getRealTimeLogs((data)=>{
            // do something when some checkin 
            console.log('real time', data)
        })
    } catch (e) {
        console.log("realtime error", e)
    }
}

test()

when I try to log, I found that checkNotEventTCP on getRealTimeLogs return CMD_ACK_OK not EF_ATTLOG or CMD_REG_EVENT

what should I do to make getRealTimeLogs working?

getAttendances() is not consistent

It seems like the data that is returned by getAttendances is not consistent. If you run it multiple times you should notice that the data that is being returned is not the same, nor is the randomness entailing any meaning at all. It seems like there is some race condition happening when reading the data from the device, which is causing it to truncate the read stream or something.

I sometimes get 22 records and sometimes 5, then sometimes 4 records; all this is without any new attendances done.

Any idea why?

Log in check

How to get the data if the client check-in or check-out the premise in getAttences?

Attendance data is not consistent

Sometimes it gets all data, and sometimes it doesn't with an error like this: "TIME OUT !! 14 PACKETS REMAIN". This is random and the amount of packets remaining is random ranging from 1 to n. I have tried a package in python and it consistently gets all the data. So I don't there is an internal device issue.
Device is: zk face702
info: {userCounts: 80, logCounts: 27538, logCapacity: 120000}
trying to get attendance data by getAttendances()

NodeRed

Hi there, is it possible to use this in nodered? How can it be achieved?

How to add a new user?

Hi,

How to add a new user with executeCmd(command , data) ? please an example. thank you

ZKError: TIMEOUT_ON_WRITING_MESSAGE upon client socket reconnect.

Good day! I'm attempting to connect multiple devices and use socket.io to emit data to client side. At first load of the server everything works fine, It say's "ok tcp" and "ok udp" but after/upon reloading the client app im having a problem with the udp type device. Here is the error:

 ZKError {
      err: Error: TIMEOUT_ON_WRITING_MESSAGE
      at Timeout.<anonymous> (C:\workspace\zktime-logs\backend\node_modules\node-zklib\zklibudp.js:101:20)
      at listOnTimeout (internal/timers.js:531:17)
      at processTimers (internal/timers.js:475:7),
      ip: 'XXX.XXX.XX.XX',
      command: '[UDP] undefined'
 }

Here is my code below:

constructor(server) {
    this.io = sio.listen(server);
    this.io
      .on("connection", (socket) => {
        devices.forEach(async (device, index) => {
          const zkInstance = new ZKLib(device.ip, 4370, 10000, 4000);
          try {
            await zkInstance.createSocket();
            console.log(await zkInstance.getInfo());

            await zkInstance.getRealTimeLogs((data) => {
              console.log(data);
            });
          } catch (e) {
            console.log(e);
            if (e.code === 'EADDRINUSE') {
            }
          }
        });
      });
  }

Thank you in advance for the help!

zklibtcp getAttendaces error on line 306

zklibtcp.js:306
cb(replyData.length, size);
^
TypeError: cb is not a function
at Socket.handleOnData (C:\Users\KMCS\Documents\node-zklib-v2\zklibtcp.js:306:17)

    const attendances = await zkInstance.getAttendances('10.20.0.7', (percent, total)=>{
        // this callbacks take params is the percent of data downloaded and total data need to download 
    })

How to add a user with fingerprint

Hello, i'm new to zk this library is worth gold to me but still can't figure alot of things..
i will be needing to add users from computer with fingerprints,
bulk delete expired users

CMD_OPTIONS_RRQ returns = instead 2 in some instances.

I am attempting to get some options from the device, using the CMD_OPTIONS_RRQ command. I get the following data back:

����~SerialNumber=ACYN174660341�
��l�����~Platform=ZLM60_TFT�
��������~DeviceName= �
��������~ProductTime==017-11-20 09:17:33�
��U�����~ZKFPVersion=10�
��0M����TCPPort=4370�
��������IPAddress=19=.168.1.42�

As can be seen in ProductTime and IPAddress the character '2' is converted to '='. Any idea what could be causing this?

Does this package support ZKTeco F18?

I have a ZKTeco F18 that I want to work with, Their SDK and programs work fine with it but I can't connect with this library, is there any solution or does this package support that version?

How to get realtime log ?

I uncommented the getRealtimelogs function and ran the code with node test.js. But I am not getting the realtime logs, what is the proper way to get it . However I am getting the users and attendance log

getAttendaces error

$ node test.js
{ userCounts: 2, logCounts: 34, logCapacity: 100000 }
check resply <Buffer 50 50 82 7d 10 00 00 00 dc 05 1b aa b6 4a 05 00 54 05 00 00 f8 ff 00 00>
check resply <Buffer 50 50 82 7d 5c 05 00 00 dd 05 58 3a 00 00 05 00 50 05 00 00 2c 00 34 31 30 32 31 33 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 2
b 2d 9a ... 1330 more bytes>
C:\Users\csulit\Documents\GitHub\node-zklib\zklibtcp.js:304
cb && cb(replyData.length, size);

Using TCP on port 80

If I try to set the port to TCP80 instead of UDP4370
let zkInstance = new ZKLib(192.168.1.202, 80, 10000, 4000);

I get the follwing error:

ZKError {
err: Error: TIMEOUT_ON_WRITING_MESSAGE
at Timeout. (nodejs\node_modules\node-zklib\zklibtcp.js:100:22)
at listOnTimeout (internal/timers.js:549:17)
at processTimers (internal/timers.js:492:7),
ip: '192.168.1.202',
command: 'TCP CONNECT'
}

is there any other considerations to take into account to use TCP instead of UDP?

the reason of using TCP is to get more user info (password, cardID) which are not available through UDP

thanks

It shows me error in decodetcpheader method

ok tcp
Waiting for the debugger to disconnect...
F:\zkteco\zklib\node_modules\node-zklib\zklibtcp.js:234
const header = decodeTCPHeader(reply.subarray(0, 16))
^

TypeError: Cannot read properties of null (reading 'subarray')
at F:\zkteco\zklib\node_modules\node-zklib\zklibtcp.js:234:44

Node.js v21.1.0

getting all device data

when i use get getAttendances function its getting logs for this month only for example from 31/10/2020 to 30/11/2020
i what to get ather months data or get all logs data and with in my code i will do some thind with this data my self please i need help with this

How to realtime events ,Get device real-time events

Hello big coffee, I would like to ask, how do I register for real-time events? I executed it with a command (zkInstance.executeCmd (500, ‘’)) and nothing happened. I want to get real-time feedback from the device, such as user ’s card swipe, user authentication, etc. . . . Very need user swipe card or fingerprint operation event

Type of data needed

can this be a string of bio id? or data needs to be converted??

async executeCmd(command, data=''){
return await this.functionWrapper(
()=> this.zklibTcp.executeCmd(command, data),
()=> this.zklibUdp.executeCmd(command , data)
)
}

// unlock the door  
executeCmd(CMD.CMD_DELETE_USERTEMP, object?)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.