node-zklib icon indicating copy to clipboard operation
node-zklib copied to clipboard

Getting Attendance Data

Open tahseenafzal opened this issue 5 years ago • 10 comments

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

showing result:

[Object Object], [Object Object]

how to read it

tahseenafzal avatar Jun 04 '20 13:06 tahseenafzal

can you show your code, when I use getAttendances() , it will return attendances object with data and error (if it has )

caobo171 avatar Jun 12 '20 16:06 caobo171

Hi :)

Thanks for this great package!

Trying out and also have an issue with that method (all other is fine, some small things about string data, will do PRs :)

However with that method (getAttendances), using the sample code (smallest repro :)

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

all I can get back:

ZKError { err: Error: TIMEOUT_ON_RECEIVING_REQUEST_DATA at Timeout._onTimeout (/home/pierre/zklib/node_modules/node-zklib/zklibtcp.js:133:20) at listOnTimeout (internal/timers.js:554:17) at processTimers (internal/timers.js:497:7), ip: '169.254.202.38', command: '[TCP] undefined' } before I go back debug, I was wondering if that rings a bell to you?

using: platform: 'ZLM60_TFT', version: '10'

It is called 'THAI01' here, but it is surely the same model everywhere only with localization,

Best,

pierrejoye avatar Oct 06 '20 12:10 pierrejoye

Ah and this comes too (only when calling getAttendances)

``

(node:11608) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'subarray' of null

at /home/pierre/zklib/node_modules/node-zklib/zklibtcp.js:234:44

at emitUnhandledRejectionWarning (internal/process/promises.js:168:15)

at processPromiseRejections (internal/process/promises.js:247:11)

at processTicksAndRejections (internal/process/task_queues.js:94:32)

(node:11608) TypeError: Cannot read property 'subarray' of null at /home/pierre/zklib/node_modules/node-zklib/zklibtcp.js:234:44

(node:11608) [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. at emitDeprecationWarning (internal/process/promises.js:180:11)

at processPromiseRejections (internal/process/promises.js:249:13)

at processTicksAndRejections (internal/process/task_queues.js:94:32

``

pierrejoye avatar Oct 06 '20 12:10 pierrejoye

Also (was trying it before)

https://github.com/vodvud/php_zklib/blob/master/zklib/src/Attendance.php works.

So I suppose some part about the size of the data is not correct ending up with waiting for too much data.

pierrejoye avatar Oct 06 '20 12:10 pierrejoye

I confirm it is the parsing of the incoming data being wrong.

I am not that quick with JS as I am with C or other, but I will try to debug.

Also most recent devices provide a status field, which defines what kind of clock in/out was done. The full data from the attendance log looks like (json for the example): { "uid": 26, "user_id": "1", "timestamp": 1602042126.0, "status": 1, "punch": 0 }

I will try this week to provide a standalone script using executecommand with a new parser (at least for the data stream)

pierrejoye avatar Oct 07 '20 03:10 pierrejoye

ok.

Case 1: Empty Attendance produces:

ZKError {
  err: Error: TIMEOUT_ON_RECEIVING_REQUEST_DATA
      at Timeout._onTimeout (/home/pierre/projects/pos/node-zklib/node_modules/node-zklib/zklibtcp.js:133:20)
      at listOnTimeout (internal/timers.js:554:17)
      at processTimers (internal/timers.js:497:7),
  ip: '169.254.202.38',
  command: '[TCP] undefined'
}

pierrejoye avatar Oct 07 '20 06:10 pierrejoye

The 2nd error, will update once figured out what causes it (it appears whether the attendance is empty or not)

pierrejoye avatar Oct 07 '20 06:10 pierrejoye

For the empty log error:

WIthout the TCP Header, the data is:

{ "0": 80, "1": 80, "2": 130, "3": 125, "4": 8, "5": 0, "6": 0, "7": 0, "8": 125, "9": 19, "10": 95, "11": 32, "12": 30, "13": 204, "14": 5, "15": 0, }

in zklibtcp.js:132

if(header.commandId === COMMANDS.CMD_DATA){

fails, heading to the false clause on line 136:

      const packetLength = data.readUIntLE(4, 2)
      if (packetLength > 8) {

as the packetLength == 8, timeout is not renew, catching the timeout catch and error out.

the header.commandId is: 4989

pierrejoye avatar Oct 07 '20 07:10 pierrejoye

I need help, getAttendances() only get a few data, but i need all history data, ¿how can i do it?

WalterPrz avatar Apr 21 '23 20:04 WalterPrz