JubaerHossain / zk-jubaer

zk-jubaer is a Node.js library that provides a simple and intuitive API for interacting with ZK BioMetric Fingerprint Attendance Devices. It enables developers to retrieve device information, add new users, retrieve real-time logs, and clear the attendance logs stored on the device
21 stars 5 forks source link

Realtime Logs not getting data #3

Open abdullahrehmanse opened 7 months ago

abdullahrehmanse commented 7 months ago

Hi Jubaer, getUsers, and getAttendances works fine but the getRealTimeLogs function is not working, it doesn't console anything when I check-in. Following is my demo code:

const express = require('express');
const app = express();
const port = 3000;

app.get('/', (req, res) => {
    res.send('Hello, World!');
});

app.listen(port, () => {
    console.log(`Server is listening at http://localhost:${port}`);
});

const ZKJUBAER = require("zk-jubaer");

const runMachine = async () => {
    let obj = new ZKJUBAER("192.168.0.3", 4370, 5200, 5000);
    try {
        // Create socket to machine
        await obj.createSocket();

        // Get all logs in the machine
        const logs = await obj.getAttendances();
        console.log(logs);

        // Read real-time logs
        await obj.getRealTimeLogs((data) => {
            console.log(data);
        });

        // Disconnect from device
        await obj.disconnect(); // when you are using real-time logs, you need to disconnect manually
    } catch (e) {
        console.log(e);
    }
};

runMachine();
abdullahrehmanse commented 7 months ago

I am using Uface800plus

Kireq1 commented 6 months ago

hi abdulla you can resolve your problem because me too have this problem maybe this can help.

I am working to acquire the registration reports for an access control and attendance model SpeedFace-V5L from the zkteco brand. I have another K20 model device and the code works perfectly, it can recover information about the device, user, and most importantly the attendance records, but when trying the same on the SpeedFace-V5L it recovers information about the device, users, but not the sold records. . Already review the structure of the library and it is very simple, there is a function that is responsible for reading all the outputs of the socket after connecting to the device. This connection collects all the available elements, as follows:

requestData(msg) { return new Promise((resolve, reject) => { let timer = null let replyBuffer = Buffer.from([]) const internalCallback = (data) => { this.socket.removeListener('data', handleOnData) timer && clearTimeout(timer) resolve(data) } const handleOnData = (data) => { replyBuffer = Buffer.concat([replyBuffer, data]) if (checkNotEventTCP(data)) return; clearTimeout(timer)

const header = decodeTCPHeader(replyBuffer.subarray(0,16));

if(header.commandId === COMMANDS.CMD_DATA){
  timer = setTimeout(()=>{
    internalCallback(replyBuffer)
  }, 1000)
}else{
  timer = setTimeout(() => {
    reject(new Error('TIMEOUT_ON_RECEIVING_REQUEST_DATA'))
  }, this.timeout)

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

} the variable responseBuffer = Buffer.concat([replyBuffer, data]) is responsible for storing available elements that the socket throws through the buffer into an array, when debugging the contestBuffer array of the k20 device it contains 27 elements, while the device SpeedFace- V5L only selects 16, the curious thing here is that when pairing selects the elements under the 'data' statement that is declared in: const internalCallback = (data) => { this.socket.removeListener('data', handleOnData) timer && clearTimeout(timer) resolve (data) } My theory is that it must be identified if another keyword or something else is required for the new equipment that can help me identify or know what is required to consult the registration data, since it is very clear that it marks the error. which refers to an unestablished stay. only opting for 16 elements when in the previous equipment you opt for 27 elements, in the same way and if it helps anyone, I share the API Development Manual: AMTMultiBio SDK For Windows which is the official zkteco manual: https://new-website-file.s3.ap-southeast-1.amazonaws.com/files/20230313/Armatura%20SDK%20Guide_MultiBio%202.1_Windows-202206.pdf